By default Yii uses PHP as template language, but you can configure it to support other rendering engines, such as
By default, Yii uses PHP as its template language, but you can configure Yii to support other rendering engines, such as
[Twig](http://twig.sensiolabs.org/) or [Smarty](http://www.smarty.net/).
[Twig](http://twig.sensiolabs.org/) or [Smarty](http://www.smarty.net/).
The `view` component is responsible for rendering views. You can add a custom template engines by reconfiguring this
The `view` component is responsible for rendering views. You can add a custom template engine by reconfiguring this
component's behavior:
component's behavior:
```php
```php
...
@@ -30,22 +30,21 @@ component's behavior:
...
@@ -30,22 +30,21 @@ component's behavior:
]
]
```
```
In the config above we're using Smarty and Twig. In order to get these extensions in your project you need to modify
In the code above, both Smarty and Twig are configured to be useable by the view files. But in order to get these extensions into your project, you need to also modify
your `composer.json`to include
your `composer.json`file to include them, too:
```
```
"yiisoft/yii2-smarty": "*",
"yiisoft/yii2-smarty": "*",
"yiisoft/yii2-twig": "*",
"yiisoft/yii2-twig": "*",
```
```
That code would be added to the `require` section of `composer.json`. After making that change and saving the file, you can install the extensions by running `composer update --preder-dist` in the command-line.
in `require` section and then run `composer update --preder-dist`.
Twig
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).
To use Twig, you need to create templates in files that have the `.twig` extension (or use another file extension but configure the component accordingly).
Unlike standard view files, when using Twig, you must include the extension when calling`$this->render()`
Unlike standard view files, when using Twig you must include the extension in your`$this->render()`
Additional filters may be added via config's `filters` option:
Additional filters may be added via the application configuration's `filters` option:
```php
```php
'filters'=>[
'filters'=>[
...
@@ -96,7 +95,7 @@ Additional filters may be added via config's `filters` option:
...
@@ -96,7 +95,7 @@ Additional filters may be added via config's `filters` option:
],
],
```
```
Then in the template you can use
Then in the template you can use:
```
```
{{ model|jsonEncode }}
{{ model|jsonEncode }}
...
@@ -106,8 +105,8 @@ Then in the template you can use
...
@@ -106,8 +105,8 @@ Then in the template you can use
Smarty
Smarty
------
------
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()`
To use Smarty, you need to create templates in files that have 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 in your`$this->render()`