Commit f0c080bf by Alexander Makarov

Fixes #1323: updated template engines guide section

parent ca4a12fd
Using template engines Using template engines
====================== ======================
By default Yii uses PHP as template language, but you can configure it to support other rendering engines, such as [Twig](http://twig.sensiolabs.org/) or [Smarty](http://www.smarty.net/). By default Yii uses PHP as template language, but you can configure it to support other rendering engines, such as
[Twig](http://twig.sensiolabs.org/) or [Smarty](http://www.smarty.net/).
The `view` component is responsible for rendering views. You can add The `view` component is responsible for rendering views. You can add a custom template engines by reconfiguring this
a custom template engines by reconfiguring this component's behavior: component's behavior:
```php ```php
[ [
...@@ -13,11 +14,13 @@ a custom template engines by reconfiguring this component's behavior: ...@@ -13,11 +14,13 @@ a custom template engines by reconfiguring this component's behavior:
'class' => 'yii\web\View', 'class' => 'yii\web\View',
'renderers' => [ 'renderers' => [
'tpl' => [ 'tpl' => [
'class' => 'yii\renderers\SmartyViewRenderer', 'class' => 'yii\smarty\ViewRenderer',
//'cachePath' => '@runtime/Smarty/cache',
], ],
'twig' => [ 'twig' => [
'class' => 'yii\renderers\TwigViewRenderer', 'class' => 'yii\twig\ViewRenderer',
'twigPath' => '@app/vendors/Twig', //'cachePath' => '@runtime/Twig/cache',
//'options' => [], /* Array of twig options */
], ],
// ... // ...
], ],
...@@ -26,7 +29,15 @@ a custom template engines by reconfiguring this component's behavior: ...@@ -26,7 +29,15 @@ a custom template engines by reconfiguring this component's behavior:
] ]
``` ```
Note that the Smarty and Twig packages themselves are not bundled with Yii. You must download them yourself. Then unpack the packages and place the resulting files in a logical location, such as the application's `protected/vendor` folder. Finally, specify the correct `smartyPath` or `twigPath`, as in the code above (for Twig). In the config above we're using Smarty and Twig. In order to get these extensions in your project you need to modify
your `composer.json` to include
```
"yiisoft/yii2-smarty": "*",
"yiisoft/yii2-twig": "*",
```
in `require` section and then run `composer update`.
Twig Twig
---- ----
......
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