php – Yii2如何将布局文件拆分为单独的页眉和页脚?

前端之家收集整理的这篇文章主要介绍了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的官方范例:

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 calling beginContent() and endContent() 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() and endContent(). The parameter passed to beginContent() 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

原文链接:https://www.f2er.com/php/133054.html

猜你在找的PHP相关文章