cancel
Showing results for 
Search instead for 
Did you mean: 

Help with overwriting .phtml file in Magento 2.2.7

SOLVED
   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

Help with overwriting .phtml file in Magento 2.2.7

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

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Help with overwriting .phtml file in Magento 2.2.7

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!

View solution in original post

7 REPLIES 7

Re: Help with overwriting .phtml file in Magento 2.2.7

Hi @connor_ferry,

Please follow below blog once, it will help you.


How to override template-phtml files in magento-2

Re: Help with overwriting .phtml file in Magento 2.2.7

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:Smiley Tongueroduct/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.

Re: Help with overwriting .phtml file in Magento 2.2.7

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. 

Re: Help with overwriting .phtml file in Magento 2.2.7

here's my module structure

Screenshot 2019-06-19 at 12.38.47.png

 

 

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>
I really don't know what else I can do....


Re: Help with overwriting .phtml file in Magento 2.2.7

Following block should be:

<argument name="template" xsi:type="string">UNBXD_CategoryBanner::catalog/category/description.phtml</argument>

 

Re: Help with overwriting .phtml file in Magento 2.2.7

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!

Re: Help with overwriting .phtml file in Magento 2.2.7

Great...!!

Please accept as a solution, so it will help to others as well.