forked from yiisoft/yii2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
89 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,86 @@ | ||
Template | ||
======== | ||
Using template engines | ||
====================== | ||
|
||
By default Yii uses PHP as template language but you can configure it to be able | ||
to render templates with special engines such as Twig or Smarty. | ||
|
||
The component responsible for rendering a view is called `view`. You can add | ||
a custom template engines as follows: | ||
|
||
```php | ||
array( | ||
'components' => array( | ||
'view' => array( | ||
'class' => 'yii\base\View', | ||
'renderers' => array( | ||
'tpl' => array( | ||
'class' => 'yii\renderers\SmartyViewRenderer', | ||
), | ||
'twig' => array( | ||
'class' => 'yii\renderers\TwigViewRenderer', | ||
'twigPath' => '@app/vendors/Twig', | ||
), | ||
// ... | ||
), | ||
), | ||
), | ||
) | ||
``` | ||
|
||
Note that Smarty and Twig are not bundled with Yii and you have to download and | ||
unpack these yourself and then specify `twigPath` and `smartyPath` respectively. | ||
|
||
Twig | ||
---- | ||
|
||
In order to use Twig you need to put you templates in files with extension `.twig` | ||
(or another one if configured differently). | ||
Also you need to specify this extension explicitly when calling `$this->render()` | ||
or `$this->renderPartial()` from your controller: | ||
|
||
```php | ||
echo $this->render('renderer.twig', array('username' => 'Alex')); | ||
``` | ||
|
||
### Additional functions | ||
|
||
Additionally to regular Twig syntax the following is available in Yii: | ||
|
||
```php | ||
<a href="{{ path('blog/view', {'alias' : post.alias}) }}">{{ post.title }}</a> | ||
``` | ||
|
||
path function calls `Html::url()` internally. | ||
|
||
### Additional variables | ||
|
||
- `app` = `\Yii::$app` | ||
- `this` = current `View` object | ||
|
||
Smarty | ||
------ | ||
|
||
In order to use Smarty you need to put you templates in files with extension `.tpl` | ||
(or another one if configured differently). | ||
Also you need to specify this extension explicitly when calling `$this->render()` | ||
or `$this->renderPartial()` from your controller: | ||
|
||
```php | ||
echo $this->render('renderer.tpl', array('username' => 'Alex')); | ||
``` | ||
|
||
### Additional functions | ||
|
||
Additionally to regular Smarty syntax the following is available in Yii: | ||
|
||
```php | ||
<a href="{path route='blog/view' alias=$post.alias}">{$post.title}</a> | ||
``` | ||
|
||
path function calls `Html::url()` internally. | ||
|
||
### Additional variables | ||
|
||
- `$app` = `\Yii::$app` | ||
- `$this` = current `View` object | ||
|
This file was deleted.
Oops, something went wrong.