3

I have created a custom XML layout page that I will be using for my home page. Right now it is a clone of the normal 1column.xml layout, and I'm trying to add a container for an image slider.

Here is the code I have added to my layout file (home_page.xml):

<container name="slider.container" htmlTag="div" htmlId="slider.container" htmlClass="slider-container" before="page.top"/>

This should in theory produce the following HTML code on the home page:

<div class="slider-container" id="slider.container"> </div>

However, absolutely nothing is happening. I cannot find the container when inspecting all of the elements on the page with the F12 console. I have also added some test CCS to "slider-container" just to be sure, and absolutely nothing is showing.

My custom XML layout page should be working fine. If I remove the footer or header container from the layout file, and flush the cache, they disappear from the page as they should. This tells me that everything is set up and working correctly, but something isn't working correctly within the file.

2 Answers 2

0

The main problem is: <div class="slider-container" id="slider.container"></div> did not rendered when it have not any child element in it. You must set block in this container. Ex:

<container name="slider.container" htmlTag="div" htmlId="slider.container" htmlClass="slider-container" before="page.top">
     <block class="Magento\Framework\View\Element\Template" after="-" name="abc" template="PATH_YOUR_TEMPLATE" />
</container>

Or you can use <move> element with destination is 'slider.container' (name of container) to have child element in it.

0

Clear cache and page_cache may help you fix this problem

<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
</head>
<body>
    <referenceContainer name="content">  
        <container name="slider.container" htmlTag="div" htmlId="slider.container" htmlClass="slider-container" before="">
            <block class="Vendor\Module\Block\ExampleBlock" name="block.slider" as="slider.cms" template="Vendor_MOdule::yourblocktemplate.phtml" after="-" />
        </container>
    </referenceContainer>
</body>

Your Answer

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

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