1

I am trying to add custom template file in category list page.

app/design/frontend/Vendor/Theme/Magento_Catalog/layout/catalog_category_view.xml

<referenceContainer name="content">
        <block class="Magento\Framework\View\Element\Template" name="custom.block" template="Magento_Catalog::product/myCustomFile.phtml" />
    </referenceContainer>

This is loading the template in list page.

But i need to load it from my custom module.

I used below code to implement it.

app/code/Vendor/Module/view/frontend/layout/module_index_index.xml

 <referenceContainer name="content">
    <block class="Magento\Framework\View\Element\Template" name="custom.block" template="Vendor_Module::product/myCustomFile.phtml" />
</referenceContainer>

This is not loading my template in category list page. After using layout update also.

Can anyone help me on this please

  • Can you try to add it at app/code/Vendor/Module/view/frontend/layout/catalog_category_view.xml ? – amitshree Dec 31 '18 at 10:23
  • @amitshree, yes i need to add custom block in category page. yes tried it, that didn't work – jafar pinjar Dec 31 '18 at 10:36
  • This should work. Check here magento.stackexchange.com/a/181719/9169 – amitshree Dec 31 '18 at 10:40
  • @amitshree, yes now it worked, thanks, the content of that phtml is like below, can we implement it there, magento.stackexchange.com/questions/256230/… – jafar pinjar Dec 31 '18 at 10:49
  • Yes you can do that with some customisation. You need to call current category and sub-categories and render them as per your need. – amitshree Dec 31 '18 at 10:53
2

create catalog_category_view.xml in your layout folder

app/code/Vendor/Module/view/frontend/layout/catalog_category_view.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>
        <css src="Addify_ProductSold::css/sales_style.css"/>
    </head>
    <body>
        <referenceContainer name="content">
            <block class="Magento\Framework\View\Element\Template" name="custom.block" template="Vendor_Module::product/myCustomFile.phtml" before="-" />

        </referenceContainer>
    </body>
</page>
  • how to move this block outside the content, like before footer – jafar pinjar Jan 9 '19 at 9:23
1

You need to add code like below.

<?xml version="1.0"?>
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>  
        <referenceContainer name="content">
            <block class="Magento\Framework\View\Element\Template" name="custom.block" template="Vendor_ModuleName::product/myCustomFile.phtml" />
        </referenceContainer>
    </body>
</page>

Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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