Show particular Block on the particular URL/page only
-
28-02-2021 - |
Вопрос
I am newcomer in Magento development, after 2 weeks I still feeling lost in the Magento 2 world.
I have added following Block to the app/design/frontend/Mojambe/LuarBiasa/Magento_Theme/layout/default.xml:
<referenceContainer name="columns.top">
<block class="Mojambe\Blog\Block\Html\MainImage" name="page.main.title" template="Mojambe_Blog::html/mainimage.phtml"/>
</referenceContainer>
My proble is the block keep showing on all the pages when I only want it to show on the Home page only.
How to make a particular block only show on the particular page/url in magento 2.3 ?
I have tried this as well but still no luck:
Any help would be very appreciated.
Решение
Finally I got the Answer, to add a Block to particular page (in my case home page) just add following line in the page content:
<p>{{block class="Mojambe\Blog\Block\Html\MainImage" template="Mojambe_Blog::html/mainimage.phtml"}}</p>
Please don't confuse with widget, block use class instead off type in the property.
First line is Block and second line is Widget.