Home>Article>Backend Development> Does php use the yii template engine?
Using Template Engine
By default, Yii uses PHP as its default template engine language , however, you can configure Yii to support other rendering engines in an extended manner, such as Twig or Smarty. (Recommended learning:PHP programming from entry to proficiency)
The component view is used to render the view. You can reconfigure the behavior of this component to add a custom template engine.[ 'components' => [ 'view' => [ 'class' => 'yii\web\View', 'renderers' => [ 'tpl' => [ 'class' => 'yii\smarty\ViewRenderer', //'cachePath' => '@runtime/Smarty/cache', ], 'twig' => [ 'class' => 'yii\twig\ViewRenderer', 'cachePath' => '@runtime/Twig/cache', // Array of twig options: 'options' => [ 'auto_reload' => true, ], 'globals' => ['html' => '\yii\helpers\Html'], 'uses' => ['yii\bootstrap'], ], // ... ], ], ],]In the above code, both Smarty and Twig are configured for use by the view file. However, in order to install the extension into the project, you also need to modify your composer.json file, as follows:
"yiisoft/yii2-smarty": "*", "yiisoft/yii2-twig": "*",The above code needs to be added to the require section of composer.json. After making the above modifications and saving them, you can run the composer update --prefer-dist command to install the extension.
The above is the detailed content of Does php use the yii template engine?. For more information, please follow other related articles on the PHP Chinese website!