0

I am trying to override template of Magento_Review module

I added new layout file under my module

app/code/Custom/CustomReview/view/frontend/layout/review_product_list.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">
    <update handle="catalog_product_view"/>
    <body>
        <referenceBlock name="product.info.product_additional_data">
            <action method="setTemplate">
                <argument name="template" xsi:type="string">Custum_CustomReview::product/view/list.phtml</argument>
            </action>
        </referenceBlock>
    </body>
</page>

and template file

app/code/Custom/CustomReview/view/frontend/templates/product/view/list.phtml

<h1>Overriding</h1>

and ny module.xml file look like below

    <?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Custom_CustomReview" setup_version="1.0.1">
        <sequence>
            <module name="Magento_Review"/>
        </sequence>
    </module>
</config>

But my template is not getting override. I cleared cache but no luck. Can anyone help what I am doing wrong here.

Thanks

4 Answers 4

3

You need to override review_product_listajax.xml in your module. And add below code only. It will work!

<?xml version="1.0"?>

<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/layout_generic.xsd">
    <referenceBlock name="product.info.product_additional_data">
        <action method="setTemplate">
            <argument name="template" xsi:type="string">Company_ModuleName::product/view/list.phtml</argument>
        </action>
    </referenceBlock>
</layout>

Flush cache and check.

7
  • Yeah but still not work :( I made review_product_list.xml but no luck
    – Daniel_12
    Jun 3, 2018 at 12:57
  • Have you created your custom theme? Jun 3, 2018 at 13:00
  • no!! custom module. I dnt want to override it in theme
    – Daniel_12
    Jun 3, 2018 at 13:01
  • Mate, check I have updated code. Jun 4, 2018 at 5:52
  • Thanks @sarvesh :) But the $review variable is not aviable in overrided template do I need to do something more to make $review variable accessible in my template
    – Daniel_12
    Jun 4, 2018 at 6:48
0

Try it

<?xml version="1.0"?>
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/layout_generic.xsd">
        <update handle="catalog_product_view"/>
        <body>
            <referenceBlock name="product.info.product_additional_data">
                <arguments>
                    <argument name="template" xsi:type="string">Custum_CustomReview::product/view/list.phtml</argument>
                </arguments>
            </referenceBlock>
        </body>
    </page>

update :

<?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">
    <update handle="catalog_product_view"/>
    <body>
        <block class="Write_Class_your_block" name="product.info.product_additional_data" template="Custum_CustomReview::product/view/list.phtml"/>
    </body>
</page>
12
  • nop I doesn't work for me
    – Daniel_12
    Jun 3, 2018 at 11:12
  • Then redefine the block, this will trigger 100%. Jun 3, 2018 at 11:13
  • how to redefine ? can you please tel me
    – Daniel_12
    Jun 3, 2018 at 11:14
  • try again, as I wrote back. I updated the answer. Jun 3, 2018 at 11:28
  • do I need to make block ?
    – Daniel_12
    Jun 3, 2018 at 11:31
0

Try this:

 <?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">
    <update handle="catalog_product_view"/>
    <body>
        <referenceBlock name="product.info.additional">
            <arguments>
                    <argument name="template" xsi:type="string">Custum_CustomReview::product/view/list.phtml</argument>
                </arguments>
        </referenceBlock>
    </body>
</page>
0

You don't nee to create a new module just to override a template. override it in your current theme instead.

To override the xml review_product_list.xml :

app/design/frontend/{Vendor}/{themeName}/Magento_Review/layout/override/base/review_product_list.xml

To override the a template :

app/design/frontend/{Vendor}/{themeName}/templates/product/view/list.phtml

Good luck.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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