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?
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?
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>
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>
Magento_Cms/layout
and then create with xml with cms_index_index.xml