PHP Class yii\twig\ViewRenderer

Since: 2.0
Author: Alexander Makarov ([email protected])
Inheritance: extends yii\base\ViewRenderer
Datei anzeigen Open project: yiisoft/yii2-twig Class Usage Examples

Public Properties

Property Type Description
$cachePath the directory or path alias pointing to where Twig cache will be stored. Set to false to disable templates cache.
$extensions Custom extensions. Example: ['Twig_Extension_Sandbox', new \Twig_Extension_Text()]
$filters Custom filters. Keys of the array are names to call in template, values are names of functions or static methods of some class. Example: ['rot13' => 'str_rot13', 'jsonEncode' => '\yii\helpers\Json::encode']. In the template you can use it like this: {{ 'test'|rot13 }} or {{ model|jsonEncode }}.
$functions Custom functions. Keys of the array are names to call in template, values are names of functions or static methods of some class. Example: ['rot13' => 'str_rot13', 'a' => '\yii\helpers\Html::a']. In the template you can use it like this: {{ rot13('test') }} or {{ a('Login', 'site/login') | raw }}.
$globals Objects or static classes. Keys of the array are names to call in template, values are objects or names of static classes. Example: ['html' => '\yii\helpers\Html']. In the template you can use it like this: {{ html.a('Login', 'site/login') | raw }}.
$lexerOptions Twig lexer options. Example: Smarty-like syntax: php [ 'tag_comment' => ['{*', '*}'], 'tag_block' => ['{', '}'], 'tag_variable' => ['{$', '}'] ]
$options Twig options.
$twig twig environment object that renders twig templates
$twigFallbackPaths twig fallback paths
$twigModulesNamespace twig namespace to use in modules templates
$twigViewsNamespace twig namespace to use in templates
$twigWidgetsNamespace twig namespace to use in widgets templates
$uses namespaces and classes to import. Example: php [ 'yii\bootstrap', 'app\assets', \yii\bootstrap\NavBar::className(), ]

Public Methods

Method Description
addExtensions ( array $extensions ) Adds custom extensions
addFilters ( array $filters ) Adds custom filters
addFunctions ( array $functions ) Adds custom functions
addGlobals ( array $globals ) Adds global objects or static classes
init ( )
render ( View $view, string $file, array $params ) : string Renders a view file.
setLexerOptions ( array $options ) Sets Twig lexer options to change templates syntax

Protected Methods

Method Description
addAliases ( Twig_Loader_Filesystem $loader, array $aliases ) Adds aliases
addFallbackPaths ( Twig_Loader_Filesystem $loader, Theme | null $theme ) Adds fallback paths to twig loader

Private Methods

Method Description
_addCustom ( string $classType, array $elements ) Adds custom function or filter

Method Details

addAliases() protected method

Adds aliases
protected addAliases ( Twig_Loader_Filesystem $loader, array $aliases )
$loader Twig_Loader_Filesystem
$aliases array

addExtensions() public method

Adds custom extensions
public addExtensions ( array $extensions )
$extensions array @see self::$extensions

addFallbackPaths() protected method

Adds fallback paths to twig loader
Since: 2.0.5
protected addFallbackPaths ( Twig_Loader_Filesystem $loader, Theme | null $theme )
$loader Twig_Loader_Filesystem
$theme yii\base\Theme | null

addFilters() public method

Adds custom filters
public addFilters ( array $filters )
$filters array @see self::$filters

addFunctions() public method

Adds custom functions
public addFunctions ( array $functions )
$functions array @see self::$functions

addGlobals() public method

Adds global objects or static classes
public addGlobals ( array $globals )
$globals array @see self::$globals

init() public method

public init ( )

render() public method

This method is invoked by [[View]] whenever it tries to render a view. Child classes must implement this method to render the given view file.
public render ( View $view, string $file, array $params ) : string
$view yii\base\View the view object used for rendering the file.
$file string the view file.
$params array the parameters to be passed to the view file.
return string the rendering result

setLexerOptions() public method

Sets Twig lexer options to change templates syntax
public setLexerOptions ( array $options )
$options array @see self::$lexerOptions

Property Details

$cachePath public_oe property

the directory or path alias pointing to where Twig cache will be stored. Set to false to disable templates cache.
public $cachePath

$extensions public_oe property

Custom extensions. Example: ['Twig_Extension_Sandbox', new \Twig_Extension_Text()]
public $extensions

$filters public_oe property

Custom filters. Keys of the array are names to call in template, values are names of functions or static methods of some class. Example: ['rot13' => 'str_rot13', 'jsonEncode' => '\yii\helpers\Json::encode']. In the template you can use it like this: {{ 'test'|rot13 }} or {{ model|jsonEncode }}.
public $filters

$functions public_oe property

Custom functions. Keys of the array are names to call in template, values are names of functions or static methods of some class. Example: ['rot13' => 'str_rot13', 'a' => '\yii\helpers\Html::a']. In the template you can use it like this: {{ rot13('test') }} or {{ a('Login', 'site/login') | raw }}.
public $functions

$globals public_oe property

Objects or static classes. Keys of the array are names to call in template, values are objects or names of static classes. Example: ['html' => '\yii\helpers\Html']. In the template you can use it like this: {{ html.a('Login', 'site/login') | raw }}.
public $globals

$lexerOptions public_oe property

Twig lexer options. Example: Smarty-like syntax: php [ 'tag_comment' => ['{*', '*}'], 'tag_block' => ['{', '}'], 'tag_variable' => ['{$', '}'] ]
See also: http://twig.sensiolabs.org/doc/recipes.html#customizing-the-syntax
public $lexerOptions

$options public_oe property

Twig options.
See also: http://twig.sensiolabs.org/doc/api.html#environment-options
public $options

$twig public_oe property

twig environment object that renders twig templates
public $twig

$twigFallbackPaths public_oe property

twig fallback paths
Since: 2.0.5
public $twigFallbackPaths

$twigModulesNamespace public_oe property

twig namespace to use in modules templates
Since: 2.0.5
public $twigModulesNamespace

$twigViewsNamespace public_oe property

twig namespace to use in templates
Since: 2.0.5
public $twigViewsNamespace

$twigWidgetsNamespace public_oe property

twig namespace to use in widgets templates
Since: 2.0.5
public $twigWidgetsNamespace

$uses public_oe property

namespaces and classes to import. Example: php [ 'yii\bootstrap', 'app\assets', \yii\bootstrap\NavBar::className(), ]
public $uses