Skip to content

TemplateLayer

A template layer wraps information necessary to render a template.

abstract class TemplateLayer extends ParameterHolder

ExtendsParameterHolder
Since1.0.0
SourceView/TemplateLayer.php
PropertyTypeDescription
$contextmixedprotected.
$contextNamemixedprotected.
$renderermixedprotected.
$slotsmixedprotected. Slots are always SlotRenderables: setSlot() is the only writer and rejects anything else outright (the legacy execution-container form is gone).

public function __construct(array<string, mixed> $parameters = []): mixed

Constructor.

Initial parameters.

ParameterTypeDescription
$parametersarray``<``string``, ``mixed``>Initial parameters.

Returns mixed

MethodDescription
__clone(): mixedObject cloning callback.
__sleep(): mixedPre-serialization callback.
__wakeup(): mixedPost-unserialization callback.
[`execute(Renderer $renderer = null, array<string, mixed> &$attributes = [], array<intstring, mixed> &$moreAssigns = []): string`](#execute)
getModule(): ?stringGet the name of the module this layer’s template belongs to.
getName(): ?stringGet the name of this layer.
getRenderer(): ?RendererGet the renderer instance used for this layer.
getResourceStreamIdentifier(): ?stringGet the full, resolved stream location name to the template resource.
[`getSlot(string $name): SlotRenderablenull`](#getslot)
getSlots(): array<string, SlotRenderable>Get all slots.
getTemplate(): ?stringGet the name of the template to render.
hasSlot(string $name): boolCheck whether or not a slot has been set.
hasSlots(): boolCheck if any slots have been set.
hasTemplate(): boolCheck whether a template has been set.
initialize(Context $context, array<string, mixed> $parameters = []): voidInitialize the layer.
removeSlot(string $name): voidRemove a slot.
removeTemplate(): voidRemove the configured template.
reset(): voidDrops the per-request rendering state so the layer can be reused.
setModule(?string $module): voidSet the name of the module this layer’s template belongs to.
setName(?string $name): voidSet the name of this layer.
setRenderer(Renderer $renderer): voidSet a renderer instance to use for this layer.
[`setSlot(string $name, SlotRenderablestring $c): void`](#setslot)
setTemplate(?string $template): voidSet the name of the template to render.

public function __clone(): mixed

Object cloning callback.

Will clone each individual slot (which are execution containers).

Returns mixed

public function __sleep(): mixed

Pre-serialization callback.

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

Returns mixed

public function __wakeup(): mixed

Post-unserialization callback.

Will restore the context based on the names set by __sleep.

Returns mixed

public function execute(Renderer $renderer = null, array<string, mixed> &$attributes = [], array<int|string, mixed> &$moreAssigns = []): string

A convenience function that renders all slots and then the main template.

Associative array of additional assigns.

ParameterTypeDescription
$rendererRendererAn optional renderer instance that will be used instead of the one set on the layer.
$attributesarray``<``string``, ``mixed``>The template variables.
$moreAssigns`array<int“string, mixed>`

Returns string — The rendered result.

public function getModule(): ?string

Get the name of the module this layer’s template belongs to.

Returns ?``string — The module name, or null if not set.

ThrowsWhen
QuioteExceptionIf the “module” parameter is set but is not a string.

public function getName(): ?string

Get the name of this layer.

Returns ?``string — The layer name, or null if not set.

ThrowsWhen
QuioteExceptionIf the “name” parameter is set but is not a string.

public function getRenderer(): ?Renderer

Get the renderer instance used for this layer.

Returns ?Renderer — A renderer instance.

abstract public function getResourceStreamIdentifier(): ?string

Get the full, resolved stream location name to the template resource.

Returns ?``string — A PHP stream resource identifier, or null if no template is set.

ThrowsWhen
ExceptionIf the template could not be found.

public function getSlot(string $name): SlotRenderable|null

Get the execution container for a slot.

The name of the slot.

ParameterTypeDescription
$namestringThe name of the slot.

Returns SlotRenderable|``null — The slot’s renderable, or null if no slot with that name is set.

public function getSlots(): array<string, SlotRenderable>

Get all slots.

Returns array``<``string``, SlotRenderable> — An associative array of slot renderables, keyed by slot name.

public function getTemplate(): ?string

Get the name of the template to render.

Returns ?``string — The template name, or null if not set.

ThrowsWhen
QuioteExceptionIf the “template” parameter is set but is not a string.

public function hasSlot(string $name): bool

Check whether or not a slot has been set.

The name of the slot.

ParameterTypeDescription
$namestringThe name of the slot.

Returns bool — True if the slot exists, false otherwise.

public function hasSlots(): bool

Check if any slots have been set.

Returns bool — true if any slots are defined, false otherwise.

public function hasTemplate(): bool

Check whether a template has been set.

Returns bool — True if a template is set, false otherwise.

public function initialize(Context $context, array<string, mixed> $parameters = []): void

Initialize the layer.

An array of initialization parameters.

ParameterTypeDescription
$contextContextThe current Context instance.
$parametersarray``<``string``, ``mixed``>An array of initialization parameters.

public function removeSlot(string $name): void

Remove a slot.

The name of the slot.

ParameterTypeDescription
$namestringThe name of the slot.

public function removeTemplate(): void

Remove the configured template.

public function reset(): void

Drops the per-request rendering state so the layer can be reused.

Releases the context and its name, the renderer and any registered slots, then delegates to the parent for the parameter state and finally unsets the layer name, template attributes and extra assigns.

public function setModule(?string $module): void

Set the name of the module this layer’s template belongs to.

The module name.

ParameterTypeDescription
$module?``stringThe module name.

public function setName(?string $name): void

Set the name of this layer.

The layer name.

ParameterTypeDescription
$name?``stringThe layer name.

public function setRenderer(Renderer $renderer): void

Set a renderer instance to use for this layer.

A renderer instance.

ParameterTypeDescription
$rendererRendererA renderer instance.

public function setSlot(string $name, SlotRenderable|string $c): void

Set a slot that is rendered along with and available inside this layer.

Deprecated legacy container parameter now supports SlotRenderable only.

ParameterTypeDescription
$namestringThe name of the slot.
$cSlotRenderable`“string`

public function setTemplate(?string $template): void

Set the name of the template to render.

The template name.

ParameterTypeDescription
$template?``stringThe template name.

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.
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.
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.