介绍 入门 应用结构 请求处理 关键概念 配合数据库工作 接收用户数据 显示数据 安全 缓存 RESTfulWeb服务 开发工具 测试 高级专题 小部件 助手类 其他

发布于 2015-08-01 11:22:09 | 377 次阅读 | 评论: 0 | 来源: 网络整理

By default, Yii uses PHP as its template language, but you can configure Yii to support other rendering engines, such as Twig or Smarty available as extensions.

The view component is responsible for rendering views. You can add a custom template engine by reconfiguring this component's behavior:

[
    'components' => [
        'view' => [
            'class' => 'yiiwebView',
            'renderers' => [
                'tpl' => [
                    'class' => 'yiismartyViewRenderer',
                    //'cachePath' => '@runtime/Smarty/cache',
                ],
                'twig' => [
                    'class' => 'yiitwigViewRenderer',
                    'cachePath' => '@runtime/Twig/cache',
                    // Array of twig options:
                    'options' => [
                        'auto_reload' => true,
                    ],
                    'globals' => ['html' => 'yiihelpersHtml'],
                    'uses' => ['yiibootstrap'],
                ],
                // ...
            ],
        ],
    ],
]

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 file to include them, too:

"yiisoft/yii2-smarty": "*",
"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 --prefer-dist in the command-line.

For details about using concrete template engine please refer to its documentation:

最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务