Documentation
¶
Overview ¶
Package view renders html/template views with layouts, partials and fragments (single blocks, for htmx), plus request-aware helpers: route, asset, csrfField, old, errors, flash, cspNonce, t and locale.
Layout of the views directory:
layouts/app.html {{block "content" .}}{{end}} inside the page shell
partials/nav.html included with {{template "partials/nav" .}}
components/alert.html same, by convention for reusable widgets
posts/index.html a page: {{define "content"}}...{{end}}
A page uses the default layout ("app") unless its first line is a comment naming another one: {{/* layout: admin */}} or {{/* layout: none */}}.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// FS holds the views (os.DirFS("resources/views") or an embed.FS).
FS fs.FS
// Ext is the view file extension (default ".html").
Ext string
// DefaultLayout is used by pages without a layout comment (default
// "app"; ignored when layouts/app.html does not exist).
DefaultLayout string
// Reload re-parses views on every render (development).
Reload bool
// Funcs adds custom template functions.
Funcs template.FuncMap
// URLs resolves named routes for the "route" function.
URLs web.URLGenerator
// AssetPrefix is prepended by "asset" (default "/").
AssetPrefix string
// Vite backs the "vite" and "viteReactRefresh" functions; "asset"
// resolves files Vite processed through it first.
Vite *vite.Vite
// I18n backs the "t" and "locale" functions, in the locale that
// i18n.Middleware stored in the request context (the bundle's default
// otherwise). Without it, the bundle in the context is used, and "t"
// returns the key when there is none.
I18n *i18n.Bundle
}
Config configures an Engine.
Click to show internal directories.
Click to hide internal directories.