3

I'm trying to display some static content in home page using default.xml.

But that content is loading in all pages of magento2.

I want the static content on home page only.

Can anyone help me to solve this issue using default.xml?

Aasim Goriya
  • 5,444
  • 2
  • 28
  • 53

2 Answers2

1

On same location create cms_index_index.xml and add your code init.

for example :

<?xml version="1.0"?>

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="content">
            <block class="yourBLockClass" name="YourBLockName" template="YourPhtmlPath.phtml">
            </block>
        </referenceContainer>
    </body>
</page>
Teja Bhagavan Kollepara
  • 3,816
  • 5
  • 32
  • 69
Murtuza Zabuawala
  • 14,814
  • 9
  • 44
  • 75
0

Try this.

Add your phtml file in cms_index_index.xml(/app/design/frontend/{theme vendor}/{themename}/Magento_Cms/layout/cms_index_index.xml) layout file because cms_index_index is handler which calls only called at home.

If you don't have Magento_Cms folder under your theme you need to create that with Magento_Cms/layout/cms_index_index.xml with below code.

<?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">
    <body>
         {{Your XML code will here}}
    <body/>
</page>
kunj
  • 3,699
  • 2
  • 10
  • 25