0

I'm trying to add containers/blocks to a newly created page layout. However, they do not show up in the DOM at all:

vendor/my/module/view/frontend/layouts.xml:

<page_layouts xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/PageLayout/etc/layouts.xsd">
 <layout id="new-layout">
 <label translate="true">New layout</label>
 </layout>
</page_layouts>

I can select this layout. That works.

vendor/my/module/view/frontend/page_layout/new-layout.xml:

 <?xml version="1.0"?>
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_layout.xsd">
 <update handle="1column"/>
 <referenceContainer name="page.wrapper">
 <container name="cake" label="CAKE" htmlTag="div" htmlClass="cake" before="-"/>
 </referenceContainer>
</layout>

That container doesn't show up. So I try adding a block..

vendor/my/module/view/frontend/layout/default.xml:

<?xml version="1.0"?>
<page layout="new-layout" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
 <body>
 <referenceContainer name="cake">
 <block class="Magento\Theme\Block\Html\Breadcrumbs" name="breadcrumbs" as="breadcrumbs" template="Magento_Theme::html/breadcrumbs.phtml"/>
 </referenceContainer>
 </body>
</page>

Nothing of all this shows up in the DOM..


Edit:

The problem was that the breadcrumb referenceBlock was set to remove="true" for all CMS pages. However, for this new layout I want to undo this with remove="false". This doesn't seem to work. I also tried re-adding the block:

<block class="Magento\Theme\Block\Html\Breadcrumbs" name="test.breadcrumbs"/>

But this doesn't work. It loads the template but there are no $crumbs found so they aren't loaded. If I remove the 'remove="true"' the breadcrumbs DO show.. I want it just to show for this layout. Why don't my 2 suggested solutions work?

asked Aug 30, 2017 at 11:35

1 Answer 1

0

In Layout file like default.xml or any other request handler file. You need to mention Layout Id as well like below:

<page layout="new-layout" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
answered Aug 30, 2017 at 12:33
10
  • Thank you, I've updated my answer. Can you check what the problem could be? Commented Aug 30, 2017 at 13:14
  • you can change the name of block like: <block class="Magento\Theme\Block\Html\Breadcrumbs" name="breadcrumbs_other" as="breadcrumbs_other" template="Magento_Theme::html/breadcrumbs.phtml"/> Commented Aug 30, 2017 at 13:44
  • I did that. I called it test.breadcrumbs in my example. Commented Aug 30, 2017 at 14:00
  • with complete template path ? Commented Aug 30, 2017 at 14:01
  • Yes. If I write some text in the template file, it does display. However, everything in <?php if ($crumbs && is_array($crumbs)) : ?> doesn't show. Commented Aug 30, 2017 at 14:07

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.