Documentation
¶
Overview ¶
Package tmpl handles loading and rendering HTML templates.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetFlash ¶
func SetFlash(w http.ResponseWriter, flash Flash)
SetFlash sets a flash message using a cookie. Flash messages can also be set when rendering the response, but since this will not work for redirects or methods without a response, sometimes we need to set a cookie and read the value from there.
Types ¶
type Page ¶
type Page struct { Title string Path string URL *url.URL Domain string Host string XSRF string Lang language.Tag Printer *message.Printer Flash Flash UID int // Data may be set by a template renderer when the template is executed // and should not be set by callers of this package (except by setting the // extraData parameters on a template renderer). // It will contain data that can only be known at render time and not when the // renderer is constructed (which may or may not be the same). Data interface{} }
Page represents data that can apply generally to any page.
type RenderFunc ¶
type RenderFunc func(uid int, flash Flash, w http.ResponseWriter, r *http.Request, extraData interface{}) error
RenderFunc is the type used to render templates into pages. For more information see Renderer.
func Renderer ¶
func Renderer(domain, xsrfKey, tmplName, title string, tmpls Template, data func(Page) interface{}) RenderFunc
Renderer returns a function that can be used to render pages using the provided templates.
The data function is used to construct the data passed to the template (which should embed the provided Page). If it is nil, the page is used. If xsrfKey is provided, an XSRF token is constructed and passed to the page. If a flash message is passed to the returned function, it is displayed immediately and overrides any flash message set in a cookie (without clearing the cookie). To set a flash message in a cookie (eg. to persist it across a redirect) see SetFlash.
type Template ¶
Template wraps an "html/template".Template and adds internationalization and live reloading functionality for easy development.
func New ¶
New creates a new set of HTML templates from *.tmpl files found in the root of a virtual filesystem. If dev mode is on, templates are live-reloaded instead of being pre-generated.