Documentation
¶
Overview ¶
Package view renders Go html/template files for hex web apps.
The Engine loads *.gotmpl templates from an fs.FS (typically an //go:embed of web/views/) at construction and exposes:
- Render — full-page rendering, satisfies echo.Renderer so handlers can call c.Render(200, "pages/home", data).
- Partial — renders a named {{ define }} block only, suited to HTMX responses that swap fragments instead of full pages.
Templates use standard html/template syntax, so layouts and partials compose via {{ template "name" . }}. hex ships no additional syntax or helpers — consumers add funcs via WithFuncs.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine holds a parsed template set + optional per-render helpers.
func New ¶
New parses every template file under the given FS matching the configured extension. Templates are named by their path relative to the scan root, minus the extension. So a file at `web/views/pages/home.gotmpl` (with fsys rooted at `web/views/`) registers as `pages/home`.
func (*Engine) Lookup ¶
Lookup returns the underlying *template.Template for name. Nil when not found. Exposed for consumers who need to hold onto a specific template (e.g. for tests or lower-level rendering).
func (*Engine) Names ¶
Names returns the sorted list of registered template names for error messages and debugging.
type Option ¶
type Option func(*config)
Option configures a new Engine.
func WithExtension ¶
WithExtension registers a template file extension. Files ending with ext are loaded and parsed as plain html/template source. Call multiple times to accept several extensions; call WithPreprocessor instead for extensions that need translation (Jade/Pug, Markdown, ...).
The default engine accepts ".gotmpl" only.
func WithPreprocessor ¶
func WithPreprocessor(ext string, fn Preprocessor) Option
WithPreprocessor registers a Preprocessor for files matching ext. The preprocessor's output is fed to html/template. Useful for:
- Jade/Pug (github.com/Joker/jade) via hex/view/jade
- Markdown via any markdown-to-html transformer
- Mustache-like DSLs that need translation
Multiple extensions with different preprocessors can coexist — call WithPreprocessor once per extension.
type Preprocessor ¶
Preprocessor converts arbitrary template source (e.g. Jade/Pug, Markdown) to html/template-compatible source before the Engine parses it. name is the template's path relative to the view root (useful for error messages); source is the raw file contents.
Return the html/template string plus any error. A nil error with an empty string is treated as "skip this template".
Directories
¶
| Path | Synopsis |
|---|---|
|
Package jade wires github.com/Joker/jade into hex/view as a template Preprocessor.
|
Package jade wires github.com/Joker/jade into hex/view as a template Preprocessor. |
|
Package md wires github.com/yuin/goldmark into hex/view as a Markdown → HTML Preprocessor.
|
Package md wires github.com/yuin/goldmark into hex/view as a Markdown → HTML Preprocessor. |
|
Package provider installs a hex/view Engine as the *web.Server's echo.Renderer and binds the engine under "view" in the container.
|
Package provider installs a hex/view Engine as the *web.Server's echo.Renderer and binds the engine under "view" in the container. |