I need some advice how to overwrite category description 'block?' from file /app/design/frontend/Mgs/mgsblank/Magento_Catalog/templates/category/description.phtml
I want to use my own module which I've created. I've tried many tutorials but still doesn't work.
Basically I need to load my custom description.phtml with my module. Appreciate any help
Solved! Go to Solution.
Yeah I've managed to make it works!
Final code
<?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance dc" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <referenceBlock name="category.description"> <action method="setTemplate"> <argument name="template" xsi:type="string">UNBXD_CategoryBanner::catalog/category/description.phtml </argument> </action> </referenceBlock> </page>
I made mistake with path to my phtml file!
Hi @connor_ferry,
Please follow below blog once, it will help you.
based on this tutorial:
2. Using Module Level,
You can override template file using the Module level.
You need to create layout XML file from your controller action,
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" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="category.products.list">
<arguments>
<argument name="template" xsi:type="string">Vendor_Module:roduct/list.phtml</argument>
</arguments>
</referenceBlock>
</body>
</page>
I have no idea how should I call referenceBlock name to match category view
I tried category.description with no luck.
category.description should work.
because in default file there is same name.
<block class="Magento\Catalog\Block\Category\View" name="category.description" template="Magento_Catalog::category/description.phtml"/
Make sure that you have flushed cache after change and static-content redeployed.
here's my module structure
Also catalog_category_view.xml
<?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance dc" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <referenceBlock name="category.description"> <action method="setTemplate"> <argument name="template" xsi:type="string">UNBXD_CategoryBanner::view/frontend/templates/catalog/category/description.phtml </argument> </action> </referenceBlock> </page>
Following block should be:
<argument name="template" xsi:type="string">UNBXD_CategoryBanner::catalog/category/description.phtml</argument>
Yeah I've managed to make it works!
Final code
<?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance dc" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <referenceBlock name="category.description"> <action method="setTemplate"> <argument name="template" xsi:type="string">UNBXD_CategoryBanner::catalog/category/description.phtml </argument> </action> </referenceBlock> </page>
I made mistake with path to my phtml file!
Great...!!
Please accept as a solution, so it will help to others as well.