StringTemplateTrait
Adds string template functionality to any class by providing methods to load and parse string templates.
This trait requires the implementing class to provide a config()
method for reading/updating templates. An implementation of this method
is provided by Cake\Core\InstanceConfigTrait
Table of Contents
Properties
- $_templater : StringTemplate|null
- StringTemplate instance.
Methods
- formatTemplate() : string
- Formats a template string with $data
- getTemplates() : array<string|int, mixed>|string
- Gets templates to use or a specific template.
- setTemplates() : $this
- Sets templates to use.
- templater() : StringTemplate
- Returns the templater instance.
Properties
$_templater
StringTemplate instance.
protected
StringTemplate|null
$_templater
Methods
formatTemplate()
Formats a template string with $data
public
formatTemplate(string $name, array<string, mixed> $data) : string
Parameters
- $name : string
-
The template name.
- $data : array<string, mixed>
-
The data to insert.
Return values
stringgetTemplates()
Gets templates to use or a specific template.
public
getTemplates([string|null $template = null ]) : array<string|int, mixed>|string
Parameters
- $template : string|null = null
-
String for reading a specific template, null for all.
Return values
array<string|int, mixed>|stringsetTemplates()
Sets templates to use.
public
setTemplates(array<string|int, string> $templates) : $this
Parameters
- $templates : array<string|int, string>
-
Templates to be added.
Return values
$thistemplater()
Returns the templater instance.
public
templater() : StringTemplate