PHP 클래스 Cake\View\StringTemplate

Used by several helpers to provide simple flexible templates for generating HTML and other content.
상속: use trait Cake\Core\InstanceConfigTrait
파일 보기 프로젝트 열기: cakephp/cakephp 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$_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