php – Yii2如何将布局文件拆分为单独的页眉和页脚?
我是新来的YII2,所以这可以是非常基本的问题.
我已经设置了初始申请.我有我的YII2应用程序/主题/标准的设置主题 现在,有一个默认的布局文件themes / standard / layouts / main.php – 这有标题和页脚的html代码 我想将标题分成主题/标准/布局/ header.php和页脚到另一个文件 我在main.php中尝试过如下代码 <?php $this->render("header"); ?> 也试过了这个 <?php $this->render("//layouts/header"); ?> 但它没有呈现内容.
为了拥有嵌套布局,您可以使用下面的beginContent()和endContent()(例如在您的main.php布局中):
<?php $this->beginContent('@app/views/layouts/header.php'); ?> <!-- You may need to put some content here --> <?php $this->endContent(); ?> 在头和尾之间的一切都将被替换为header.php中的$content. 截至Yii2的官方范例:
<?php $this->beginContent('@app/views/layouts/base.php'); ?> ...child layout content here... <?php $this->endContent(); ?>
http://www.yiiframework.com/doc-2.0/guide-structure-views.html#nested-layouts (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |