template

package
v0.0.0-...-baa204d Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2022 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompileTemplates

func CompileTemplates(filenames []string, funcs map[string]interface{}) (*template.Template, error)

CompileTemplates minifies then parses each file in filenames.

Types

type Template

type Template struct {
	Template *template.Template
	// contains filtered or unexported fields
}

A Template wraps go's html/template to provide easier use.

func NewTemplate

func NewTemplate(tmplPath string, funcs map[string]interface{}) (t *Template, err error)

NewTemplate creates a new Template object. It will attempt to parse the templates available (*.tmpl files) in the given path and its subdirectories.

func (*Template) LoadTemplates

func (t *Template) LoadTemplates() (err error)

LoadTemplates loads templates (files ending in .tmpl) from a given directory and all its subdirectories.

func (*Template) ReloadTemplates

func (t *Template) ReloadTemplates(next http.Handler) http.Handler

ReloadTemplates is a middleware that calls LoadTemplates. It's useful during development to live reload templates in development but shouldn't be used in production.

func (*Template) RenderTemplate

func (t *Template) RenderTemplate(w http.ResponseWriter, name string, data interface{})

RenderTemplate calls ExecuteTemplate on the passed template name. If the template fails to render then render the status code 500 page

func (*Template) RenderToString

func (t *Template) RenderToString(name string, data interface{}) (result string, err error)

RenderToString calls ExecuteTemplate on the passed template name.

Jump to

Keyboard shortcuts

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