templates

package
v6.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2022 License: AGPL-3.0, Apache-2.0 Imports: 8 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetTemplateDirectory

func GetTemplateDirectory() (string, bool)

Types

type Container

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

Container represents a set of templates that can be render

func New

func New(directory string) (*Container, error)

New creates a new templates container scanning a directory.

func NewFromTemplate

func NewFromTemplate(templates *template.Template) *Container

NewFromTemplates creates a new templates container using a `template.Template` object

func NewWithWatcher

func NewWithWatcher(directory string) (*Container, <-chan error, error)

NewWithWatcher creates a new templates container scanning a directory and watch the directory filesystem changes to apply them to the loaded templates. This function returns the container and an errors channel to pass all errors that can happen during the watch process, or an regular error if we fail to create the templates or the watcher. The caller must consume the returned errors channel to ensure not blocking the watch process.

func (*Container) Close

func (c *Container) Close()

Close stops the templates watcher of the container in case you have created it with watch parameter set to true

func (*Container) Render

func (c *Container) Render(w io.Writer, templateName string, data Data) error

RenderToString renders the template referenced with the template name using the data provided and write it to the writer provided

func (*Container) RenderToString

func (c *Container) RenderToString(templateName string, data Data) (string, error)

RenderToString renders the template referenced with the template name using the data provided and return a string with the result

type Data

type Data struct {
	Props map[string]interface{}
	HTML  map[string]template.HTML
}

Data contains the data used to populate the template variables, it has Props that can be of any type and HTML that only can be `template.HTML` types.

Jump to

Keyboard shortcuts

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