TemplateLayer
A template layer wraps information necessary to render a template.
Synopsis
Section titled “Synopsis”abstract class TemplateLayer extends ParameterHolder
| Extends | ParameterHolder |
| Since | 1.0.0 |
| Source | View/TemplateLayer.php |
Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
$context | mixed | protected. |
$contextName | mixed | protected. |
$renderer | mixed | protected. |
$slots | mixed | protected. Slots are always SlotRenderables: setSlot() is the only writer and rejects anything else outright (the legacy execution-container form is gone). |
Constructor
Section titled “Constructor”__construct()
Section titled “__construct()”public function __construct(array<string, mixed> $parameters = []): mixed
Constructor.
Initial parameters.
| Parameter | Type | Description |
|---|---|---|
$parameters | array``<``string``, ``mixed``> | Initial parameters. |
Returns mixed
Methods
Section titled “Methods”| Method | Description |
|---|---|
__clone(): mixed | Object cloning callback. |
__sleep(): mixed | Pre-serialization callback. |
__wakeup(): mixed | Post-unserialization callback. |
| [`execute(Renderer $renderer = null, array<string, mixed> &$attributes = [], array<int | string, mixed> &$moreAssigns = []): string`](#execute) |
getModule(): ?string | Get the name of the module this layer’s template belongs to. |
getName(): ?string | Get the name of this layer. |
getRenderer(): ?Renderer | Get the renderer instance used for this layer. |
getResourceStreamIdentifier(): ?string | Get the full, resolved stream location name to the template resource. |
| [`getSlot(string $name): SlotRenderable | null`](#getslot) |
getSlots(): array<string, SlotRenderable> | Get all slots. |
getTemplate(): ?string | Get the name of the template to render. |
hasSlot(string $name): bool | Check whether or not a slot has been set. |
hasSlots(): bool | Check if any slots have been set. |
hasTemplate(): bool | Check whether a template has been set. |
initialize(Context $context, array<string, mixed> $parameters = []): void | Initialize the layer. |
removeSlot(string $name): void | Remove a slot. |
removeTemplate(): void | Remove the configured template. |
reset(): void | Drops the per-request rendering state so the layer can be reused. |
setModule(?string $module): void | Set the name of the module this layer’s template belongs to. |
setName(?string $name): void | Set the name of this layer. |
setRenderer(Renderer $renderer): void | Set a renderer instance to use for this layer. |
| [`setSlot(string $name, SlotRenderable | string $c): void`](#setslot) |
setTemplate(?string $template): void | Set the name of the template to render. |
__clone()
Section titled “__clone()”public function __clone(): mixed
Object cloning callback.
Will clone each individual slot (which are execution containers).
Returns mixed
__sleep()
Section titled “__sleep()”public function __sleep(): mixed
Pre-serialization callback.
Will set the name of the context and exclude the instance from serializing.
Returns mixed
__wakeup()
Section titled “__wakeup()”public function __wakeup(): mixed
Post-unserialization callback.
Will restore the context based on the names set by __sleep.
Returns mixed
execute()
Section titled “execute()”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.
| Parameter | Type | Description |
|---|---|---|
$renderer | Renderer | An optional renderer instance that will be used instead of the one set on the layer. |
$attributes | array``<``string``, ``mixed``> | The template variables. |
$moreAssigns | `array<int“ | string, mixed>` |
Returns string — The rendered result.
getModule()
Section titled “getModule()”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.
| Throws | When |
|---|---|
QuioteException | If the “module” parameter is set but is not a string. |
getName()
Section titled “getName()”public function getName(): ?string
Get the name of this layer.
Returns ?``string — The layer name, or null if not set.
| Throws | When |
|---|---|
QuioteException | If the “name” parameter is set but is not a string. |
getRenderer()
Section titled “getRenderer()”public function getRenderer(): ?Renderer
Get the renderer instance used for this layer.
Returns ?Renderer — A renderer instance.
getResourceStreamIdentifier()
Section titled “getResourceStreamIdentifier()”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.
| Throws | When |
|---|---|
Exception | If the template could not be found. |
getSlot()
Section titled “getSlot()”public function getSlot(string $name): SlotRenderable|null
Get the execution container for a slot.
The name of the slot.
| Parameter | Type | Description |
|---|---|---|
$name | string | The name of the slot. |
Returns SlotRenderable|``null — The slot’s renderable, or null if no slot with that name is set.
getSlots()
Section titled “getSlots()”public function getSlots(): array<string, SlotRenderable>
Get all slots.
Returns array``<``string``, SlotRenderable> — An associative array of slot renderables, keyed by slot name.
getTemplate()
Section titled “getTemplate()”public function getTemplate(): ?string
Get the name of the template to render.
Returns ?``string — The template name, or null if not set.
| Throws | When |
|---|---|
QuioteException | If the “template” parameter is set but is not a string. |
hasSlot()
Section titled “hasSlot()”public function hasSlot(string $name): bool
Check whether or not a slot has been set.
The name of the slot.
| Parameter | Type | Description |
|---|---|---|
$name | string | The name of the slot. |
Returns bool — True if the slot exists, false otherwise.
hasSlots()
Section titled “hasSlots()”public function hasSlots(): bool
Check if any slots have been set.
Returns bool — true if any slots are defined, false otherwise.
hasTemplate()
Section titled “hasTemplate()”public function hasTemplate(): bool
Check whether a template has been set.
Returns bool — True if a template is set, false otherwise.
initialize()
Section titled “initialize()”public function initialize(Context $context, array<string, mixed> $parameters = []): void
Initialize the layer.
An array of initialization parameters.
| Parameter | Type | Description |
|---|---|---|
$context | Context | The current Context instance. |
$parameters | array``<``string``, ``mixed``> | An array of initialization parameters. |
removeSlot()
Section titled “removeSlot()”public function removeSlot(string $name): void
Remove a slot.
The name of the slot.
| Parameter | Type | Description |
|---|---|---|
$name | string | The name of the slot. |
removeTemplate()
Section titled “removeTemplate()”public function removeTemplate(): void
Remove the configured template.
reset()
Section titled “reset()”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.
setModule()
Section titled “setModule()”public function setModule(?string $module): void
Set the name of the module this layer’s template belongs to.
The module name.
| Parameter | Type | Description |
|---|---|---|
$module | ?``string | The module name. |
setName()
Section titled “setName()”public function setName(?string $name): void
Set the name of this layer.
The layer name.
| Parameter | Type | Description |
|---|---|---|
$name | ?``string | The layer name. |
setRenderer()
Section titled “setRenderer()”public function setRenderer(Renderer $renderer): void
Set a renderer instance to use for this layer.
A renderer instance.
| Parameter | Type | Description |
|---|---|---|
$renderer | Renderer | A renderer instance. |
setSlot()
Section titled “setSlot()”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.
| Parameter | Type | Description |
|---|---|---|
$name | string | The name of the slot. |
$c | SlotRenderable` | “string` |
setTemplate()
Section titled “setTemplate()”public function setTemplate(?string $template): void
Set the name of the template to render.
The template name.
| Parameter | Type | Description |
|---|---|---|
$template | ?``string | The template name. |
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. |
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. |
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. |