1

My block is being included twice inside my cms page from my page layout. Here is my code:

# File: theme_dir/Magento_Theme/page_layout/homepage.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="empty"/>
    <referenceContainer name="page.wrapper">
        <block class="Magento\Framework\View\Element\Template" template="Magento_Theme::homepage.phtml" />
    </referenceContainer>
</layout>

# File: theme_dir/Magento_Theme/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="homepage">
        <label translate="true">homepage</label>
    </layout>
</page_layouts>

# File: theme_dir/Magento_Theme/templates/hompeage.phtml
<h1>Homepage Content</h1>

Of course, I have also set my home cms page to my homepage template.

When the page loads I see the phtml file included twice. Inspecting the page I see the following:

<div class="page-wrapper">
    <main id="maincontent" class="page-main"><a id="contentarea" tabindex="-1"></a>
    ...
    </main>
    <h1>Homepage Content</h1><h1>Homepage Content</h1>

I've tried changing name="page.wrapper" to other references, such as main, columns, etc., (note this required using update handle 1column instead) but the outcome is the same, the content get's included twice.

The closest success I have had is that this does not seem to happen when I use the page layout in a category page.

Is this expected behavior? How to include the block a single time?

Magento 2.1.3 CE

1

Your code looks fine; although I'd specify a name attribute for the block.

I'd suggest that you look in other places in your store for where this block could be included. I've had issues like this before where the block was actually coming both in page layout and from the Design tab in a CMS, category or product page.

2
  • You were technically right but it sounds like you weren't even aware. Apparently the name is required or else you get two blocks – jamil Feb 1 '17 at 16:29
  • @jamil huh, that is strange. Thanks for telling me! – tjons Feb 1 '17 at 16:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.