PHP Class Cake\View\StringTemplate

Used by several helpers to provide simple flexible templates for generating HTML and other content.
Inheritance: use trait Cake\Core\InstanceConfigTrait
Afficher le fichier Open project: cakephp/cakephp Class Usage Examples

Protected Properties

Свойство Type Description
$_compactAttributes array List of attributes that can be made compact.
$_compiled array Contains the list of compiled templates
$_configStack array A stack of template sets that have been stashed temporarily.
$_defaultConfig array The default templates this instance holds.

Méthodes publiques

Méthode Description
__construct ( array $config = [] ) Constructor.
add ( array $templates ) Registers a list of templates by name
format ( string $name, array $data ) : string | null Format a template string with $data
formatAttributes ( array | null $options, array | null $exclude = null ) : string 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:
get ( )
load ( string $file ) : void Load a config file containing templates.
pop ( ) : void Restore the most recently pushed set of templates.
push ( ) : void Push the current templates into the template stack.
remove ( string $name ) : void Remove the named template.

Méthodes protégées

Méthode Description
_compileTemplates ( array $templates = [] ) : void Compile templates into a more efficient printf() compatible format.
_formatAttribute ( string $key, string | array $value, boolean $escape = true ) : string Formats an individual attribute, and returns the string value of the composed attribute.

Method Details

__construct() public méthode

Constructor.
public __construct ( array $config = [] )
$config array A set of templates to add.

_compileTemplates() protected méthode

Compile templates into a more efficient printf() compatible format.
protected _compileTemplates ( array $templates = [] ) : void
$templates array The template names to compile. If empty all templates will be compiled.
Résultat void

_formatAttribute() protected méthode

Works with minimized attributes that have the same value as their name such as 'disabled' and 'checked'
protected _formatAttribute ( string $key, string | array $value, boolean $escape = true ) : string
$key string The name of the attribute to create
$value string | array The value of the attribute to create.
$escape boolean Define if the value must be escaped
Résultat string The composed attribute.

add() public méthode

### Example: $templater->add([ 'link' => '{{title}}' 'button' => '' ]);
public add ( array $templates )
$templates array An associative list of named templates.

format() public méthode

Format a template string with $data
public format ( string $name, array $data ) : string | null
$name string The template name.
$data array The data to insert.
Résultat string | null Formatted string or null if template not found.

formatAttributes() public méthode

- '1' (string) - 1 (integer) - true (boolean) - 'true' (string) 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.
public formatAttributes ( array | null $options, array | null $exclude = null ) : string
$options array | null Array of options.
$exclude array | null Array of options to be excluded, the options here will not be part of the return.
Résultat string Composed attributes.

get() public méthode

public get ( )

load() public méthode

Template files should define a $config variable containing all the templates to load. Loaded templates will be merged with existing templates.
public load ( string $file ) : void
$file string The file to load
Résultat void

pop() public méthode

Restore the most recently pushed set of templates.
public pop ( ) : void
Résultat void

push() public méthode

Push the current templates into the template stack.
public push ( ) : void
Résultat void

remove() public méthode

Remove the named template.
public remove ( string $name ) : void
$name string The template to remove.
Résultat void

Property Details

$_compactAttributes protected_oe property

List of attributes that can be made compact.
protected array $_compactAttributes
Résultat array

$_compiled protected_oe property

Contains the list of compiled templates
protected array $_compiled
Résultat array

$_configStack protected_oe property

A stack of template sets that have been stashed temporarily.
protected array $_configStack
Résultat array

$_defaultConfig protected_oe property

The default templates this instance holds.
protected array $_defaultConfig
Résultat array