Magento2 – How to Override Product Review list.phtml File

magento2

I tried,
app/design/frontend/Test/abc/Magento_Review/layout/review_product_list.xml

   <?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="page.bottom.container">
    <referenceBlock name="product.info.product_additional_data">
        <action method="setTemplate">
            <argument name="template" xsi:type="string">Magento_Review::product/view/list.phtml</argument>
        </action>
    </referenceBlock>
    </referenceContainer>
</body>
 </page>

app/design/frontend/Test/abc/Magento_Review/templates/product/view/list.phtml

<?php
    $_items = $block->getReviewsCollection()->getItems();
    $format = $block->getDateFormat() ?: \IntlDateFormatter::SHORT;
?>
<?php if (count($_items)):?>
<div class="block review-list" id="customer-reviews">
<div class="block-title">
    <strong><?php /* @escapeNotVerified */ echo __('Customer Reviews new24234') ?></strong>
</div>
<div class="block-content">
    <div class="toolbar review-toolbar">
        <?php echo $block->getChildHtml('toolbar') ?>
    </div>
    <ol class="items review-items">
    <?php foreach ($_items as $_review):?>
        <li class="item review-item" itemscope itemprop="review" itemtype="http://schema.org/Review">
            <div class="review-title" itemprop="name"><?php echo $block->escapeHtml($_review->getTitle()) ?></div>
            <?php if (count($_review->getRatingVotes())): ?>
                <div class="review-ratings">
                <?php foreach ($_review->getRatingVotes() as $_vote): ?>
                <div class="rating-summary item" itemprop="reviewRating" itemscope itemtype="http://schema.org/Rating">
                    <span class="label rating-label"><span><?php echo $block->escapeHtml($_vote->getRatingCode()) ?></span></span>
                    <div class="rating-result" title="<?php /* @escapeNotVerified */ echo $_vote->getPercent() ?>%">
                        <meta itemprop="worstRating" content = "1"/>
                        <meta itemprop="bestRating" content = "100"/>
                        <span style="width:<?php /* @escapeNotVerified */ echo $_vote->getPercent() ?>%">
                            <span itemprop="ratingValue"><?php /* @escapeNotVerified */ echo $_vote->getPercent() ?>%</span>
                        </span>
                    </div>
                </div>
                <?php endforeach; ?>
                </div>
            <?php endif; ?>
            <div class="review-content" itemprop="description">
                <?php echo nl2br($block->escapeHtml($_review->getDetail())) ?>
            </div>
            <div class="review-details">
                <p class="review-author">
                    <span class="review-details-label"><?php /* @escapeNotVerified */ echo __('Review by')?></span>
                    <strong class="review-details-value" itemprop="author"><?php echo $block->escapeHtml($_review->getNickname()) ?></strong>
                </p>
                <p class="review-date">
                    <span class="review-details-label"><?php /* @escapeNotVerified */ echo __('Posted on') ?></span>
                    <time class="review-details-value" itemprop="datePublished" datetime="<?php /* @escapeNotVerified */ echo $block->formatDate($_review->getCreatedAt(), $format) ?>"><?php /* @escapeNotVerified */ echo $block->formatDate($_review->getCreatedAt(), $format) ?></time>
                </p>
            </div>
        </li>
    <?php endforeach; ?>
    </ol>
    <div class="toolbar review-toolbar">
        <?php echo $block->getChildHtml('toolbar') ?>
    </div>
</div>
</div>
<?php endif;?>

Also created register.php, composer file and theme.xml in Test/abc folder and in backend theme is assigned.

But its not working.

Best Answer

When you place the file in the same location like you have done you extend the file, to completely override it you need to place it in the following directory:

<theme_dir>
  |__/<Namespace_Module>
    |__/layout
      |__/override
         |__/base
           |--<layout1>.xml
           |--<layout2>.xml

Or if you need to overwrite the file from a parent theme:

<theme_dir>
  |__/<Namespace_Module>
    |__/layout
      |__/override
         |__/theme
            |__/<Parent_Vendor>
               |__/<parent_theme>
                  |--<layout1>.xml
                  |--<layout2>.xml

Your example

So if you are overriding review_product_list.xml from base (the module) you would create this file:

app/design/frontend/Test/abc/Magento_Review/layout/override/base/review_product_list.xml

And if you're overriding it from a parent theme:

app/design/frontend/Test/abc/Magento_Review/layout/override/theme/PARENT-VENDOR/PARENT-THEME/review_product_list.xml

If this doesn't work I think there is a bigger problem, such as a theme not being configured properly.

You can read more about overriding XML files in the dev docs here.

Related Topic