0

i have created a custom page layout, which i have used for my homepage. But when i m trying to add a template in it my template is not showing . Given below is my layout code

<?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">
        <container name="header.container" as="header_container" label="Page Header Container"  htmlTag="header" htmlClass="page-header" before="main.content"/>
        <container name="page.top" as="page_top" label="After Page Header" after="header.container"/>
        <container name="footer-container" as="footer" before="before.body.end" label="Page Footer Container" htmlTag="footer" htmlClass="page-footer" />
    </referenceContainer>
    <referenceBlock name="page.main.title" template="Magento_Theme::components/slider/slider-image.phtml"/>
    <referenceContainer name="main.content" htmlTag="main" htmlClass="page-main-full-width" />
</layout>

Template is present in the same folder as mentioned in the block (components/slider/slider-image.phtml). But the block itself is not showing. I want to display it after the header. please help

2 Answers 2

1

Homepage customization you need to create a "cms_index_index.xml" file into your theme

Vendor/Theme/Magento_Cms/layout/cms_index_index.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <!-- add additional js or css here -->
    </head>
    <body>
        <!-- Your header/footer customization -->

        <!-- Create a separate template for slider instead of using existing one's -->
        <referenceBlock name="content">
            <block class="Magento\Framework\View\Element\Template"
                   name="home-page-slideshow"
                   template="Magento_Theme::components/slider/slider-image.phtml" />
        </referenceBlock>

        <!-- if you don't need title remove it -->
        <referenceBlock name="page.main.title" remove="true" />
    </body>
</page>

You can use the body class for homepage specific styling (cms-home or cms-index-index)

2
  • What if i m creating a another template for other pages, which are not home pages. then how the layout will be? Jan 12, 2021 at 9:19
  • @AkshayNaik there are few steps you need to follow for applying different layouts of cms pages: 1. Create a new layout file on the same path as mentioned above in your theme and use code same as above. 2. The file name should be like this > cms_page_view_selectable_[page-url-key]_[name-of-your-layout].xml e.g cms_page_view_selectable_contact-us_contactuspage.xml 3. Now edit contact us page (Content -> Pages -> Contact us). 4. Under design section select your layout "Custom Layout Update"
    – MBT
    Jan 13, 2021 at 13:15
1

Please try the below code in your.xml file

<referenceContainer name="page.top">            
    <block class="Package\Modulename\Block\Modulename" name="Modulename-main" template="Package_Modulename::Modulename.phtml"/> 
</referenceContainer>

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.