Magento2:referenceContainer和referenceBlock有什么区别


23

这两个referenceBlockreferenceContainer实体在magento2布局中。
它们之间的主要区别是什么,以及如何将这些实体与magento1。*相关联。

Answers:


38

基本上,容器与core/text_listmagento 1 中的块等效。
“从哲学上讲”,它们的工作原理相同,唯一的区别是containers预定义的块仅支持其他子块。
一些例子是contentafter.body.startheader-wrapper
您可以在中查看所有定义的容器Magento/Theme/view/base/page_layout/*

这是来自的示例empty.xml

<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_layout.xsd">
    <container name="root">
        <container name="after.body.start" as="after.body.start" before="-" label="Page Top"/>
        <container name="page.wrapper" as="page_wrapper" htmlTag="div" htmlClass="page-wrapper">
            <container name="global.notices" as="global_notices" before="-"/>
            <container name="main.content" htmlTag="main" htmlId="maincontent" htmlClass="page-main">
                <container name="columns.top" label="Before Main Columns"/>
                <container name="columns" htmlTag="div" htmlClass="columns">
                    <container name="main" label="Main Content Container" htmlTag="div" htmlClass="column main"/>
                </container>
            </container>
            <container name="page.bottom" as="page_bottom" label="Before Page Footer Container" after="main.content" htmlTag="div" htmlClass="page-bottom"/>
            <container name="before.body.end" as="before_body_end" after="-" label="Page Bottom"/>
        </container>
    </container>
</layout>

基本上<container name="..." />可以定义为referenceContainer。声明<block .... />可以被什么引用referenceBlock

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.