utils

package
v0.0.0-...-abe7528 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 15, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package utils implements utility functions and helpers for the application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RenderPage

func RenderPage(context echo.Context, title, description, contentBlock, layout string) error

RenderPage is a helper function to render a full page with a consistent structure. It sets up the data for rendering, including the page title, content block, and layout.

Parameters:

  • context: The echo.Context for the current request.
  • title: The title of the page.
  • description: The description of the page.
  • contentBlock: The name of the content block to render within the layout.
  • layout: The name of the layout template to use.

Returns:

  • An error if the rendering fails.

This function is typically used in route handlers to render full pages with a consistent structure.

Types

type Templates

type Templates struct {
	// contains filtered or unexported fields
}

Templates is a struct that holds the template environment.

func NewTemplates

func NewTemplates() *Templates

NewTemplates creates and initializes a new Templates instance. This function sets up the template environment, including:

  • Creating a base template
  • Setting up custom template functions
  • Parsing the base template file
  • Parsing all other template files in the views directory

The function uses a specific directory structure:

  • Base template: "resources/views/Base.html"
  • Other templates: "resources/views/**/*.html"

Returns:

  • A pointer to a new Templates instance.

Panics if there's an error parsing the templates.

func (*Templates) Render

func (templ *Templates) Render(writer io.Writer, name string, data interface{}, context echo.Context) error

Render is the implementation of echo.Renderer interface. It renders a template with the given name and data.

Parameters:

  • writer: The io.Writer to write the rendered template to.
  • name: The name of the template to render.
  • data: The data to pass to the template.
  • context: The echo.Context for the current request.

Returns:

  • An error if the template rendering fails.

This method adds the "Layout" key to the data map, which can be used in the base template to determine which content block to render.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL