【问题标题】:How to use Twig template engine with Yii2 framework?如何在 Yii2 框架中使用 Twig 模板引擎?
【发布时间】:2014-07-20 02:48:09
【问题描述】:

我按照 yii2 文档中关于使用 twig 模板引擎的说明进行操作

在 config/web.php(包含在 index.php 中)我有:

'view' => [
            'class' => 'yii\web\View',
            'renderers' => [
                'twig' => [
                    'class' => 'yii\twig\ViewRenderer',
                    'cachePath' => '@runtime/Twig/cache',
                    'options' => ['auto_reload' => true], /*  Array of twig options */
                    'globals' => ['html' => '\yii\helpers\Html'],
                ],
            ],
        ],

在 SiteController.php 中:

public function actionIndex()
    {
        echo $this->render('index.twig');
    }

在 views/site/index.twig 我有一些文字:

但我看到的不是原始 html,而是基于 views/layouts/main.php 的模板,其中 index.twig 内容在主布局中用作变量。

【问题讨论】:

    标签: php twig yii2


    【解决方案1】:

    为了在redner期间跳过布局处理,需要将布局设置为false

    class BaseController extends Controller
    {
        public $layout = false;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-25
      • 2011-10-27
      相关资源
      最近更新 更多