Yii2-安装smarty模板引擎及使用

Yii2-安装smarty模板引擎及使用

github地址:

https://github.com/yiisoft/yii2-smarty

命令安装:

composer require --prefer-dist yiisoft/yii2-smarty

修改web.php配置文件

return [
    //....
    'components' => [
        'view' => [
            'renderers' => [
                'tpl' => [
                    'class' => 'yii\smarty\ViewRenderer',
                    //'cachePath' => '@runtime/Smarty/cache',
                ],
            ],
        ],
    ],
];

控制器代码

public function actionIndex(){
    return $this->renderPartial('index1.tpl', ['username' => 'zhangsan']);
}

视图 index.tpl

Hello,{$username}
<br />
smarty版本:{$smarty.version}
<br />
1+1={1+1}
<br />

\

posted @ 2024-04-16 17:58  胡勇健  阅读(4)  评论(0编辑  收藏  举报