Render and Children
GoHT composes templates with @render and @children.
@rendercalls another template and passes any required parameters.- Nested content under
@renderis passed to the rendered template. @childrenrenders nested content that was passed by the caller.
These directives work in Haml, Slim, and EGO templates. EGO uses command tags such as <%@render ... %> and <%@children %>.
@render
Use @render when one template should call another template.
The same pattern in Slim:
And in EGO:
The parameters passed to @render are the parameters of the generated Go template function. If Page is generated as func Page(title string) *PageTemplate, then @render Page("Home") calls that generated function and renders the returned template.
Nested render content and @children
Nested content under @render remains in the calling template’s scope. The rendered template chooses where that content appears by using @children.
Rendered output from ArticlePage("Sam") is shaped like:
Slim uses the same = @render and = @children directives:
EGO uses command tags:
Nested content with WithChildren
children is the built-in slot that @children renders. Fill it from Go with WithChildren(...) instead of nesting content under @render when you’re composing by hand:
See Slots for named slots, which give a layout several independent content regions instead of a single children region.