Documentation
¶
Overview ¶
==== File: integrations/stdlib/stdlib.go ==== Package stdlib provides a convenience wrapper for using the templates engine with Go's standard net/http library.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Renderer ¶
Renderer provides a wrapper around templates.Templates for net/http.
func FromTemplates ¶
FromTemplates creates a new Renderer from an existing templates.Templates instance. This is useful if you have already configured a templates.Templates instance.
func New ¶ added in v1.0.4
New creates a new Renderer with the given options. It is a convenience wrapper around templates.New.
func (*Renderer) Handler ¶
func (r *Renderer) Handler(templateName string, data interface{}) http.HandlerFunc
Handler returns a http.HandlerFunc that renders the given template with the provided data. If an error occurs during rendering, it will be logged by the underlying templates.Templates instance.
func (*Renderer) HandlerWithDataFromContext ¶
func (r *Renderer) HandlerWithDataFromContext(templateName string, contextKey interface{}) http.HandlerFunc
HandlerWithDataFromContext returns a http.HandlerFunc that renders the given template, using data from the request context. The data is retrieved from the request's context using the provided contextKey. If an error occurs, it will be logged by the underlying templates.Templates instance.
func (*Renderer) Render ¶
func (r *Renderer) Render(w http.ResponseWriter, req *http.Request, status int, name string, data interface{}) error
Render executes a template, sets the HTTP status code, and writes the output to the http.ResponseWriter.
Parameters:
- w: The http.ResponseWriter to write the rendered output to.
- req: The *http.Request, used to access context for layout selection.
- status: The HTTP status code to write.
- name: The template name to render, using the "layout:page" or ":page" syntax.
- data: The data to pass to the template.