templates.Inner
- Syntax
- templates.Inner CONTEXT
- Returns
- any
- Alias
- inner
Usage
The templates.Inner function returns the result of executing the template block enclosed by a partial decorator call, using the given context. Call this function within the partial template to define where the enclosed block appears.
To call a partial template as a decorator, use a with statement in the calling template. Hugo does not render the enclosed block when it executes the with statement. Instead, the partial template renders the block each time it calls templates.Inner. The partial template controls the outer structure, while the calling template controls the inner content.
The CONTEXT argument determines the value of the dot (.) within the enclosed block. To use the context passed to the partial template, pass the dot, as in {{ templates.Inner . }}. The with statement creates a new scope, so variables defined in the calling template outside of the block are not available within it.
A partial template can call templates.Inner zero or more times. If the partial template does not call the function, Hugo does not render the enclosed block.
Examples
<div class="card">
{{ templates.Inner . }}
</div>Calling the partial template as a decorator:
{{ with partial "components/card.html" . }}
<h2>{{ .Title }}</h2>
{{ end }}Rendering the enclosed block once for each item in a collection:
<ul>
{{ range .items }}
<li>{{ templates.Inner . }}</li>
{{ end }}
</ul>Calling the partial template as a decorator, passing a collection of pages:
{{ with partial "list.html" (dict "items" site.RegularPages) }}
<a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a>
{{ end }}