Home >Backend Development >PHP Problem >Does php use the yii template engine?

Does php use the yii template engine?

(*-*)浩
(*-*)浩Original
2019-09-11 10:35:372428browse

Using Template Engine

Does php use the yii 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn