interface TemplateEngine (View source)

Interface for template rendering engines such as twig or ss templates.

Methods

public
__construct(string|array $templateCandidates = [])

Instantiate a TemplateEngine

public
setTemplate(string|array $templateCandidates)

Set the template which will be used in the call to render()

public
bool
hasTemplate(string|array $templateCandidates)

Check if there is a template amongst the template candidates that this rendering engine can use.

public
string
renderString(string $template, ViewLayerData $model, array $overlay = [], bool $cache = true)

Render the template string.

public
string
render(ViewLayerData $model, array $overlay = [])

Render the template which was selected during instantiation or which was set via setTemplate().

Details

__construct(string|array $templateCandidates = [])

Instantiate a TemplateEngine

Parameters

string|array $templateCandidates

A template or pool of candidate templates to choose from. The template engine will check the currently set themes from SSViewer for template files it can handle from the candidates.

TemplateEngine setTemplate(string|array $templateCandidates)

Set the template which will be used in the call to render()

Parameters

string|array $templateCandidates

A template or pool of candidate templates to choose from. The template engine will check the currently set themes from SSViewer for template files it can handle from the candidates.

Return Value

TemplateEngine

bool hasTemplate(string|array $templateCandidates)

Check if there is a template amongst the template candidates that this rendering engine can use.

Parameters

string|array $templateCandidates

Return Value

bool

string renderString(string $template, ViewLayerData $model, array $overlay = [], bool $cache = true)

Render the template string.

Doesn't include normalisation such as inserting js/css from Requirements API - that's handled by SSViewer.

Parameters

string $template
ViewLayerData $model

The model to get data from when rendering the template.

array $overlay

Associative array of fields (e.g. args into an include template) to inject into the template as properties. These override properties and methods with the same name from $data and from global template providers.

bool $cache

Return Value

string

string render(ViewLayerData $model, array $overlay = [])

Render the template which was selected during instantiation or which was set via setTemplate().

Doesn't include normalisation such as inserting js/css from Requirements API - that's handled by SSViewer.

Parameters

ViewLayerData $model

The model to get data from when rendering the template.

array $overlay

Associative array of fields (e.g. args into an include template) to inject into the template as properties. These override properties and methods with the same name from $data and from global template providers.

Return Value

string

Exceptions

MissingTemplateException