PHP Класс Cake\View\StringTemplate

Used by several helpers to provide simple flexible templates for generating HTML and other content.
Наследование: use trait Cake\Core\InstanceConfigTrait
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$_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.

Открытые методы

Метод Описание
__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.

Защищенные методы

Метод Описание
_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.

Описание методов

__construct() публичный метод

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

_compileTemplates() защищенный метод

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.
Результат void

_formatAttribute() защищенный метод

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
Результат string The composed attribute.

add() публичный метод

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

format() публичный метод

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.
Результат string | null Formatted string or null if template not found.

formatAttributes() публичный метод

- '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.
Результат string Composed attributes.

get() публичный метод

public get ( )

load() публичный метод

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
Результат void

pop() публичный метод

Restore the most recently pushed set of templates.
public pop ( ) : void
Результат void

push() публичный метод

Push the current templates into the template stack.
public push ( ) : void
Результат void

remove() публичный метод

Remove the named template.
public remove ( string $name ) : void
$name string The template to remove.
Результат void

Описание свойств

$_compactAttributes защищенное свойство

List of attributes that can be made compact.
protected array $_compactAttributes
Результат array

$_compiled защищенное свойство

Contains the list of compiled templates
protected array $_compiled
Результат array

$_configStack защищенное свойство

A stack of template sets that have been stashed temporarily.
protected array $_configStack
Результат array

$_defaultConfig защищенное свойство

The default templates this instance holds.
protected array $_defaultConfig
Результат array