Commit ff444c3e by Carsten Brandt

updatd TwigRenderer docs, closes #1771

parent f4bde7a2
...@@ -26,63 +26,58 @@ class ViewRenderer extends BaseViewRenderer ...@@ -26,63 +26,58 @@ class ViewRenderer extends BaseViewRenderer
* @var string the directory or path alias pointing to where Twig cache will be stored. * @var string the directory or path alias pointing to where Twig cache will be stored.
*/ */
public $cachePath = '@runtime/Twig/cache'; public $cachePath = '@runtime/Twig/cache';
/** /**
* @var array Twig options * @var array Twig options.
* @see http://twig.sensiolabs.org/doc/api.html#environment-options * @see http://twig.sensiolabs.org/doc/api.html#environment-options
*/ */
public $options = []; public $options = [];
/** /**
* @var array Objects or static classes * @var array Objects or static classes.
* Keys of array are names to call in template, values - objects or names of static class as string * Keys of the array are names to call in template, values are objects or names of static classes.
* Example: ['html' => '\yii\helpers\Html'] * Example: `['html' => '\yii\helpers\Html']`.
* Than in template: {{ html.link('Login', 'site/login') }} * In the template you can use it like this: `{{ html.a('Login', 'site/login') | raw }}`.
*/ */
public $globals = []; public $globals = [];
/** /**
* @var array Custom functions * @var array Custom functions.
* Keys of array are names to call in template, values - names of functions or static methods of some class * 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', 'link' => '\yii\helpers\Html::link'] * Example: `['rot13' => 'str_rot13', 'a' => '\yii\helpers\Html::a']`.
* Than in template: {{ rot13('test') }} or {{ link('Login', 'site/login') }} * In the template you can use it like this: `{{ rot13('test') }}` or `{{ a('Login', 'site/login') | raw }}`.
*/ */
public $functions = []; public $functions = [];
/** /**
* @var array Custom filters * @var array Custom filters.
* Keys of array are names to call in template, values - names of functions or static methods of some class * 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'] * Example: `['rot13' => 'str_rot13', 'jsonEncode' => '\yii\helpers\Json::encode']`.
* Then in template: {{ 'test'|rot13 }} or {{ model|jsonEncode }} * In the template you can use it like this: `{{ 'test'|rot13 }}` or `{{ model|jsonEncode }}`.
*/ */
public $filters = []; public $filters = [];
/** /**
* @var array Custom extensions * @var array Custom extensions.
* Example: ['Twig_Extension_Sandbox', 'Twig_Extension_Text'] * Example: `['Twig_Extension_Sandbox', 'Twig_Extension_Text']`
*/ */
public $extensions = []; public $extensions = [];
/** /**
* @var array Twig lexer options * @var array Twig lexer options.
* @see http://twig.sensiolabs.org/doc/recipes.html#customizing-the-syntax * Example: Smarty-like syntax:
* Example: Smarty-like syntax * ```php
* array( * [
* 'tag_comment' => ['{*', '*}'], * 'tag_comment' => ['{*', '*}'],
* 'tag_block' => ['{', '}'], * 'tag_block' => ['{', '}'],
* 'tag_variable' => ['{$', '}'] * 'tag_variable' => ['{$', '}']
* ) * ]
* ```
* @see http://twig.sensiolabs.org/doc/recipes.html#customizing-the-syntax
*/ */
public $lexerOptions = []; public $lexerOptions = [];
/** /**
* @var \Twig_Environment twig environment object that do all rendering twig templates * @var \Twig_Environment twig environment object that do all rendering twig templates
*/ */
public $twig; public $twig;
public function init() public function init()
{ {
$this->twig = new \Twig_Environment(null, array_merge([ $this->twig = new \Twig_Environment(null, array_merge([
'cache' => Yii::getAlias($this->cachePath), 'cache' => Yii::getAlias($this->cachePath),
'charset' => Yii::$app->charset, 'charset' => Yii::$app->charset,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment