Skip to content

TwigRenderer

Renders Twig (.twig) templates via twig/twig.

Compiled templates are cached under <core.cache_dir>/templates/twig/.

final class TwigRenderer extends Renderer implements IReusableRenderer

ExtendsRenderer
ImplementsIReusableRenderer
SourceTwigRenderer.php
MethodDescription
getStarterTemplate(): stringReturns the skeleton .twig template written for a newly scaffolded view.
render(TemplateLayer $layer, array &$attributes = [], array &$slots = [], array &$moreAssigns = []): mixedRenders the layer’s .twig template and returns the result.
reset(): voidReturns the renderer to its post-construction state for reuse.

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

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.

ParameterTypeDescription
$layerTemplateLayer
$attributesarray
$slotsarray
$moreAssignsarray

Returns mixed

ThrowsWhen
RenderExceptionif the layer carries no template.

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.

These come from an ancestor and are documented where they are declared.

MethodDeclared inDescription
appendParameter()ParameterHolderAppend a parameter.
appendParameterByRef()ParameterHolderAppend a parameter by reference.
clearParameters()ParameterHolderClear all parameters associated with this request.
getContext()RendererRetrieve the current application context.
getDefaultExtension()RendererGet the template file extension
getFlatParameterNames()ParameterHolderRetrieve an array of flattened parameter names.
getParameter()ParameterHolderRetrieve a parameter.
getParameterNames()ParameterHolderRetrieve an array of parameter names.
getParameters()ParameterHolderRetrieve an array of parameters.
hasParameter()ParameterHolderIndicates whether or not a parameter exists.
initialize()RendererInitialize this Renderer.
removeParameter()ParameterHolderRemove a parameter.
setParameter()ParameterHolderSet a parameter.
setParameterByRef()ParameterHolderSet a parameter by reference.
setParameters()ParameterHolderSet an array of parameters.
setParametersByRef()ParameterHolderSet an array of parameters by reference.