1

I need some advice on 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

Using the layout file to override the phtml file.

First way :

<referenceBlock name="category.description">
    <action method="setTemplate">
        <argument name="template" xsi:type="string">Namespace_Modulename::path/to/my/file.phtml </argument>
    </action>
</referenceBlock>

Second way(the setTemplate method is deprecated so use this method) :

<referenceBlock name="category.description" template="Namespace_Modulename::path/to/my/file.phtml"/>

Third way :

<type name="Magento\Catalog\Block\Category\View">
    <plugin name="very-unique-name" type="Namespace\Modulename\Plugin\Block" />
</type>

Namespace\Modulename\Plugin\Block

<?php
namespace Namespace\Modulename\Plugin;

class Block
{
    public function beforeToHtml(\Other\Module\Block $block)
    {
        $block->setTemplate('Namespace\Modulename::path/to/my/file.phtml');
    }
}

I hope it helps!

0

here's my file 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">MODULE_CategoryBanner::view/frontend/templates/catalog/category/description.phtml </argument>
    </action>
</referenceBlock>
</page>

But I get an error

1 exception(s):
Exception #0 (Magento\Framework\Exception\ValidatorException): Invalid template file: 'UNBXD_CategoryBanner::view/frontend/templates/catalog/category/description.phtml' in module: 'Magento_Catalog' block's name: 'category.description'
  • remove 'view/frontend/templates' from template file path in XML – Ketan Borada Jun 19 at 11:53
  • ..and now it's working!! Thanks – Amiga Jun 19 at 11:55
0

Your phtml File Path Should be view/frontend/templetes/view/frontend/templates/catalog/category/description.phtml

catalog_category_view.xml

<referenceBlock name="category.description">
    <action method="setTemplate">
          <argument name="template" xsi:type="string">MODULE_CategoryBanner::view/frontend/templates/catalog/category/description.phtml </argument>
    </action>
</referenceBlock>
0

Finally I've managed to make it work. I made mistake with path to my .phtml file

<?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>

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.