Trait 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
Property Summary
-
$_templater protected
Cake\View\StringTemplate
StringTemplate instance.
Method Summary
-
formatTemplate() public
Formats a template string with $data
-
getTemplates() public
Gets templates to use or a specific template.
-
setTemplates() public
Sets templates to use.
-
templater() public
Returns the templater instance.
-
templates() public deprecated
Gets/sets templates to use.
Method Detail
formatTemplate() ¶ public
formatTemplate(string $name, array $data): string
Formats a template string with $data
Parameters
-
string
$name The template name.
-
array
$data The data to insert.
Returns
string
getTemplates() ¶ public
getTemplates(string|null $template = null): string|array
Gets templates to use or a specific template.
Parameters
-
string|null
$template optional String for reading a specific template, null for all.
Returns
string|array
setTemplates() ¶ public
setTemplates(string[] $templates): $this
Sets templates to use.
Parameters
-
string[]
$templates Templates to be added.
Returns
$this
templater() ¶ public
templater(): Cake\View\StringTemplate
Returns the templater instance.
Returns
Cake\View\StringTemplate
templates() ¶ public
templates(string|array|null $templates = null): $this|string|array
Gets/sets templates to use.
Parameters
-
string|array|null
$templates optional null or string allow reading templates. An array allows templates to be added.
Returns
$this|string|array