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 component responsible for rendering a view is called `view`. You can add
The `view` component is responsible for rendering views. You can add
a custom template engines as follows:
a custom template engines by reconfiguring this component's behavior:
```php
```php
array(
array(
...
@@ -26,15 +26,13 @@ array(
...
@@ -26,15 +26,13 @@ array(
)
)
```
```
Note that Smarty and Twig are not bundled with Yii and you have to download and
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).
unpack these yourself and then specify `twigPath` and `smartyPath` respectively.
Twig
Twig
----
----
In order to use Twig you need to put you templates in files with extension `.twig`
To use Twig, you need to create templates in files with the `.twig` extension (or use another file extension but configure the component accordingly).
(or another one if configured differently).
Unlike standard view files, when using Twig, you must include the extension when calling `$this->render()`
Also you need to specify this extension explicitly when calling `$this->render()`
Internally, the `path()` function calls Yii's `Html::url()` method.
### Additional variables
### Additional variables
-`app` = `\Yii::$app`
Within Twig templates, you can also make use of these variables:
-`this` = current `View` object
-`app`, which equates to `\Yii::$app`
-`this`, which equates to the current `View` object
Smarty
Smarty
------
------
In order to use Smarty you need to put you templates in files with extension `.tpl`
To use Smarty, you need to create templates in files with the `.tpl` extension (or use another file extension but configure the component accordingly). Unlike standard view files, when using Smarty, you must include the extension when calling `$this->render()`
(or another one if configured differently).
Also you need to specify this extension explicitly when calling `$this->render()`