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?
1 Answer 1
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">
-
Thank you, I've updated my answer. Can you check what the problem could be?Cake– Cake2017年08月30日 13:14:57 +00:00Commented 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"/>Pankaj Pareek– Pankaj Pareek2017年08月30日 13:44:47 +00:00Commented Aug 30, 2017 at 13:44 -
I did that. I called it test.breadcrumbs in my example.Cake– Cake2017年08月30日 14:00:34 +00:00Commented Aug 30, 2017 at 14:00
-
with complete template path ?Pankaj Pareek– Pankaj Pareek2017年08月30日 14:01:01 +00:00Commented 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.Cake– Cake2017年08月30日 14:07:37 +00:00Commented Aug 30, 2017 at 14:07
Explore related questions
See similar questions with these tags.