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.
__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 stringadd( array $templates )
Registers a list of templates by name
$templater->add([ 'link' => '<a href="{{url}}">{{title}}</a>' 'button' => '<button>{{text}}</button>' ]);
$templates mixedformat( string $name , array $data )
Format a template string with $data
$name $data string|nullformatAttributes( 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 stringload( 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 )
Delete a single config key
$key Cake\Core\Exception\Exception_configRead( string|null $key )
Read a config variable
$key mixed_configWrite( string|array $key , mixed $value , boolean|string $merge false )
Write a config variable
$key $value $merge optional false Cake\Core\Exception\Exceptionconfig( string|array|null $key null , mixed|null $value null , boolean $merge true )
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 mixedCake\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->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 $value optional null mixedget( string|array|null $key null , mixed|null $value null , boolean $merge true )
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 mixedCake\Core\Exception\Exceptionprotected boolean
Whether the config property has already been configured with defaults
false
© 2005–2016 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.
http://api.cakephp.org/3.1/class-Cake.View.StringTemplate.html