From f0c080bf0e09ceb4513b0da7c6b0e84484c414b6 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Tue, 26 Nov 2013 13:06:52 +0400 Subject: [PATCH] Fixes #1323: updated template engines guide section --- docs/guide/template.md | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/docs/guide/template.md b/docs/guide/template.md index 26c9707..b4afd33 100644 --- a/docs/guide/template.md +++ b/docs/guide/template.md @@ -1,10 +1,11 @@ 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 -a custom template engines by reconfiguring this component's behavior: +The `view` component is responsible for rendering views. You can add a custom template engines by reconfiguring this +component's behavior: ```php [ @@ -13,11 +14,13 @@ a custom template engines by reconfiguring this component's behavior: 'class' => 'yii\web\View', 'renderers' => [ 'tpl' => [ - 'class' => 'yii\renderers\SmartyViewRenderer', + 'class' => 'yii\smarty\ViewRenderer', + //'cachePath' => '@runtime/Smarty/cache', ], 'twig' => [ - 'class' => 'yii\renderers\TwigViewRenderer', - 'twigPath' => '@app/vendors/Twig', + 'class' => 'yii\twig\ViewRenderer', + //'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 ----