我已经设置了初始申请.我有我的YII2应用程序/主题/标准的设置主题
现在,有一个默认的布局文件themes / standard / layouts / main.PHP – 这有标题和页脚的HTML代码
我想将标题分成主题/标准/布局/ header.PHP和页脚到另一个文件
<?PHP $this->render("header"); ?>
也试过了这个
<?PHP $this->render("//layouts/header"); ?>
<?PHP $this->beginContent('@app/views/layouts/header.PHP'); ?> <!-- You may need to put some content here --> <?PHP $this->endContent(); ?>
在头和尾之间的一切都将被替换为header.PHP中的$content.
截至Yii2的官方范例:
Sometimes you may want to nest one layout in another. For example,in different sections of a Web site,you want to use different layouts,while all these layouts share the same basic layout that generates the overall
HTML5
page structure. You can achieve this goal by callingbeginContent()
andendContent()
in the child layouts like the following:
<?PHP $this->beginContent('@app/views/layouts/base.PHP'); ?> ...child layout content here... <?PHP $this->endContent(); ?>
As shown above,the child layout content should be enclosed within
beginContent()
andendContent()
. The parameter passed tobeginContent()
specifies what is the parent layout. It can be either a layout file or alias.
Using the above approach,you can nest layouts in more than one levels.
http://www.yiiframework.com/doc-2.0/guide-structure-views.html#nested-layouts