Skip to content

PhptalRenderer

Renders PHPTAL (.tal) templates through the standalone phptal/phptal engine.

Compiled template classes are cached under <core.cache_dir>/templates/phptal/, mirroring the layout the other on-disk template caches (e.g. the config cache) use.

final class PhptalRenderer extends Renderer

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

public function __sleep(): mixed

Pre-serialization callback.

Will set the name of the context and exclude the instance from serializing.

Returns mixed

public function getStarterTemplate(): string

Returns the skeleton .tal template written for a newly scaffolded view.

The tal:content path 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 .tal template through PHPTAL and returns the result.

Attributes are pushed into the engine either individually (when extract_vars is on) or as a single array under the configured variable name; the slots array, the renderer’s own assigns and the filtered $moreAssigns are set as further template variables. The PHPTAL engine 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 PHPTAL engine — so the next render rebuilds it against the then-current cache directory and encoding parameter — 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.