TwigRenderer
Renders Twig (.twig) templates via twig/twig.
Compiled templates are cached under <core.cache_dir>/templates/twig/.
Synopsis
Section titled “Synopsis”final class TwigRenderer extends Renderer implements IReusableRenderer
| Extends | Renderer |
| Implements | IReusableRenderer |
| Source | TwigRenderer.php |
Methods
Section titled “Methods”| Method | Description |
|---|---|
getStarterTemplate(): string | Returns the skeleton .twig template written for a newly scaffolded view. |
render(TemplateLayer $layer, array &$attributes = [], array &$slots = [], array &$moreAssigns = []): mixed | Renders the layer’s .twig template and returns the result. |
reset(): void | Returns the renderer to its post-construction state for reuse. |
getStarterTemplate()
Section titled “getStarterTemplate()”public function getStarterTemplate(): string
Returns the skeleton .twig template written for a newly scaffolded view.
The printed expression follows the renderer’s current variable configuration: a bare title when extract_vars is on, otherwise title under the configured template variable.
Returns string
render()
Section titled “render()”public function render(TemplateLayer $layer, array &$attributes = [], array &$slots = [], array &$moreAssigns = []): mixed
Renders the layer’s .twig template and returns the result.
Builds the Twig variable set from the attributes (spread individually when extract_vars is on, otherwise nested under the configured template variable), the slots, the renderer’s assigns and the filtered $moreAssigns, then hands the layer’s resolved template path straight to Twig — TemplateLayerLoader treats it as a literal file path. The Twig environment is built lazily on first use and reused afterwards.
| Parameter | Type | Description |
|---|---|---|
$layer | TemplateLayer | |
$attributes | array | |
$slots | array | |
$moreAssigns | array |
Returns mixed
| Throws | When |
|---|---|
RenderException | if the layer carries no template. |
reset()
Section titled “reset()”public function reset(): void
Returns the renderer to its post-construction state for reuse.
Drops the cached Twig environment — so the next render rebuilds it against the then-current cache directory and auto_reload, strict_variables and autoescape parameters — and then lets the parent clear the layer, variable names and assigns.
Inherited methods
Section titled “Inherited methods”These come from an ancestor and are documented where they are declared.
| Method | Declared in | Description |
|---|---|---|
appendParameter() | ParameterHolder | Append a parameter. |
appendParameterByRef() | ParameterHolder | Append a parameter by reference. |
clearParameters() | ParameterHolder | Clear all parameters associated with this request. |
getContext() | Renderer | Retrieve the current application context. |
getDefaultExtension() | Renderer | Get the template file extension |
getFlatParameterNames() | ParameterHolder | Retrieve an array of flattened parameter names. |
getParameter() | ParameterHolder | Retrieve a parameter. |
getParameterNames() | ParameterHolder | Retrieve an array of parameter names. |
getParameters() | ParameterHolder | Retrieve an array of parameters. |
hasParameter() | ParameterHolder | Indicates whether or not a parameter exists. |
initialize() | Renderer | Initialize this Renderer. |
removeParameter() | ParameterHolder | Remove a parameter. |
setParameter() | ParameterHolder | Set a parameter. |
setParameterByRef() | ParameterHolder | Set a parameter by reference. |
setParameters() | ParameterHolder | Set an array of parameters. |
setParametersByRef() | ParameterHolder | Set an array of parameters by reference. |