magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

<page layout="" />

Open jameswithers opened this issue 11 years ago • 5 comments

I've got a custom theme with a custom page layout (home):

<?xml version="1.0" encoding="UTF-8" ?> 
<page_layouts xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/View/PageLayout/etc/layouts.xsd">
    <layout id="home">
        <label translate="true">Home</label>
    </layout>
</page_layouts>

home.xml:

<?xml version="1.0" encoding="UTF-8" ?> 
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_layout.xsd" />

In app/design/Vendor/theme/Magento_Theme/layout/default.xml I have:

<?xml version="1.0" encoding="UTF-8" ?> 
<page layout="home" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd" />

However when I visit the CMS home page (which has custom layout set to home), it pulls through elements from app/code/Magento/Theme/view/frontend/layout/default.xml, with an error log like:

main.INFO: Broken reference: the 'currency' element cannot be added as child to 'header.panel', because the latter doesn't exist [] []
main.INFO: Broken reference: the 'currency' tries to reorder itself towards 'store_language', but their parents are different: 'header.panel' and '' respectively. [] []

The only way I can get my app/design/Vendor/theme/Magento_Theme/layout/default.xml to work is to comment out app/code/Magento/Theme/view/frontend/layout/default.xml, which defeats the whole purpose of a custom page layout.

The aim is to get an empty page layout; in Magento 1 this was easy, but in Magento 2 this seems either impossible, or if it's possible, it appears undocumented.

jameswithers avatar Dec 31 '14 17:12 jameswithers

Removing app/design/Vendor/theme/Magento_Theme/layout/default.xml, and replacing the custom page layout with the following solves the problem:

<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_layout.xsd">
    <remove name="content"/>
    <remove name="header-wrapper"/>
    <remove name="footer"/>
    <remove name="header.panel"/>
</layout>

However I still get a series of errors in the logs:

...
main.INFO: Broken reference: the 'header.panel' element cannot be added as child to 'header.container', because the latter doesn't exist [] []
main.INFO: Broken reference: the 'head.components' element cannot be added as child to 'after.body.start', because the latter doesn't exist [] []
main.INFO: Broken reference: the 'requirejs-config' element cannot be added as child to 'after.body.start', because the latter doesn't exist [] []
main.INFO: Broken reference: the 'translate' element cannot be added as child to 'after.body.start', because the latter doesn't exist [] []
... 

Is this the proper way to approach this problem? Or is there a better/more standard way?

jameswithers avatar Jan 01 '15 02:01 jameswithers

@jameswithers, thank you for reporting this to us! We will review this issue.

vpelipenko avatar Jan 29 '15 15:01 vpelipenko

When you put default.xml file to the theme layout folder, instructions there will be added to the original file instructions. Another word you will extend original layout with your instructions.

There is no need to change original layout file to completely remove it content. You can override it in your theme: app/design/frontend/Vendor/theme/Magento_Theme/layout/override/some_layout.xml

But it's not recommended to override default.xml, as its instructions are applied to the every page in the system.

To have your custom page layout applied to the home page you can register you file in the app/code/Magento/Theme/view/frontend/layouts.xml. (There is impossible to extend this configuration on the theme level for now, this possibility will be added in upcoming releases) This layout becomes available in the design section (Admin > Content > Home Page -> Design).

Sample content of your app/design/Vendor/theme/Magento_Theme/page_layout/home.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_layout.xsd">
    <!--This will load containers declaration to avoid errors caused by possibe <move> instructions -->
    <update handle="empty"/>
    <!-- Removing not needed containers -->
    <remove name="before.body.end"/>
    <remove name="page.wrapper"/>
    <remove name="header-wrapper"/>
    <remove name="footer"/>
    <remove name="header.panel"/>
    <remove name="after.body.start"/>
    <!-- Moving "content" container to the root to get cms page content output -->
    <move element="content" destination="root" before="-" />
</layout>

You can also apply your custom page layouts to other pages, setting layout attribute in the page node in respective page configuration layout file for example customer registration page: app/design/frontend/Vendor/theme/Magento_Customer/layout/customer_account_create.xml:

<page layout="home" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
</page>

eug123 avatar Jan 29 '15 17:01 eug123

@jameswithers, did you have a chance to look at comment provided by @eug123?

vpelipenko avatar Feb 16 '15 13:02 vpelipenko

@vpelipenko Yes. The documentation isn't very clear on this subject currently, so I was able to solve with some trial and error/testing.

jameswithers avatar Feb 16 '15 18:02 jameswithers