Provides an interface for registering and inserting content into simple logic-less string templates.
Used by several helpers to provide simple flexible templates for generating HTML and other content.
$_compactAttributes protected array$_compiled protected array$_configStack protected array$_defaultConfig protected arrayFormats an individual attribute, and returns the string value of the composed attribute. Works with minimized attributes that have the same value as their name such as 'disabled' and 'checked'
Returns a space-delimited string with items of the $options array. If a key of $options array happens to be one of those listed in StringTemplate::$_compactAttributes and its value is one of:
__construct( array $config [] )
Constructor.
$config optional [] _compileTemplates( array $templates [] )
Compile templates into a more efficient printf() compatible format.
$templates optional [] _formatAttribute( string $key , string|array $value , boolean $escape true )
Formats an individual attribute, and returns the string value of the composed attribute. Works with minimized attributes that have the same value as their name such as 'disabled' and 'checked'
$key $value $escape optional true add( array $templates )
Registers a list of templates by name
$templater->add([
'link' => '<a href="{{url}}">{{title}}</a>'
'button' => '<button>{{text}}</button>'
]); $templates addClass( array|string $input , array|string $newClass , string $useIndex 'class' )
Adds a class and returns a unique list either in array or space separated
$input $newClass $useIndex optional 'class' format( string $name , array $data )
Format a template string with $data
$name $data formatAttributes( array|null $options , array|null $exclude null )
Returns a space-delimited string with items of the $options array. If a key of $options array happens to be one of those listed in StringTemplate::$_compactAttributes and its value is one of:
Then the value will be reset to be identical with key's name. If the value is not one of these 4, the parameter is not output.
'escape' is a special option in that it controls the conversion of attributes to their HTML-entity encoded equivalents. Set to false to disable HTML-encoding.
If value for any option key is set to null or false, that option will be excluded from output.
This method uses the 'attribute' and 'compactAttribute' templates. Each of these templates uses the name and value variables. You can modify these templates to change how attributes are formatted.
$options $exclude optional null load( string $file )
Load a config file containing templates.
Template files should define a $config variable containing all the templates to load. Loaded templates will be merged with existing templates.
$file remove( string $name )
Remove the named template.
$name _configDelete( string $key )
Deletes a single config key.
$key Cake\Core\Exception\Exception_configRead( string|null $key )
Reads a config key.
$key _configWrite( string|array $key , mixed $value , boolean|string $merge false )
Writes a config key.
$key $value $merge optional false True to merge recursively, 'shallow' for simple merge, false to overwrite, defaults to false.
Cake\Core\Exception\Exceptionconfig( string|array|null $key null , mixed|null $value null , boolean $merge true )
Gets/Sets the config.
Reading the whole config:
$this->config();
Reading a specific value:
$this->config('key'); Reading a nested value:
$this->config('some.nested.key'); Setting a specific value:
$this->config('key', $value); Setting a nested value:
$this->config('some.nested.key', $value); Updating multiple config settings at the same time:
$this->config(['one' => 'value', 'another' => 'value']);
$key optional null $value optional null $merge optional true Cake\Core\Exception\ExceptionconfigShallow( string|array $key , mixed|null $value null )
Merge provided config with existing config. Unlike config() which does a recursive merge for nested keys, this method does a simple merge.
Setting a specific value:
$this->configShallow('key', $value); Setting a nested value:
$this->configShallow('some.nested.key', $value); Updating multiple config settings at the same time:
$this->configShallow(['one' => 'value', 'another' => 'value']);
$key $value optional null getConfig( string|null $key null , mixed $default null )
Returns the config.
Reading the whole config:
$this->getConfig();
Reading a specific value:
$this->getConfig('key'); Reading a nested value:
$this->getConfig('some.nested.key'); Reading with default value:
$this->getConfig('some-key', 'default-value'); $key optional null $default optional null setConfig( string|array $key , mixed|null $value null , boolean $merge true )
Sets the config.
Setting a specific value:
$this->setConfig('key', $value); Setting a nested value:
$this->setConfig('some.nested.key', $value); Updating multiple config settings at the same time:
$this->setConfig(['one' => 'value', 'another' => 'value']);
$key $value optional null $merge optional true Cake\Core\Exception\Exceptionprotected array
List of attributes that can be made compact.
[
'allowfullscreen' => true,
'async' => true,
'autofocus' => true,
'autoplay' => true,
'checked' => true,
'compact' => true,
'controls' => true,
'declare' => true,
'default' => true,
'defaultchecked' => true,
'defaultmuted' => true,
'defaultselected' => true,
'defer' => true,
'disabled' => true,
'enabled' => true,
'formnovalidate' => true,
'hidden' => true,
'indeterminate' => true,
'inert' => true,
'ismap' => true,
'itemscope' => true,
'loop' => true,
'multiple' => true,
'muted' => true,
'nohref' => true,
'noresize' => true,
'noshade' => true,
'novalidate' => true,
'nowrap' => true,
'open' => true,
'pauseonexit' => true,
'readonly' => true,
'required' => true,
'reversed' => true,
'scoped' => true,
'seamless' => true,
'selected' => true,
'sortable' => true,
'truespeed' => true,
'typemustmatch' => true,
'visible' => true,
]
© 2005–2017 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/3.5/class-Cake.View.StringTemplate.html