Browse Source

Fixes #1323: updated template engines guide section

tags/2.0.0-beta
Alexander Makarov 11 years ago
parent
commit
f0c080bf0e
  1. 25
      docs/guide/template.md

25
docs/guide/template.md

@ -1,10 +1,11 @@
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:
'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:
] ]
``` ```
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
---- ----

Loading…
Cancel
Save