Question

How can override theme .phtml file override into custom module.

Path theme .phtml file is app\design\frontend\ThemeName_CompanyName\Module_Catalog\templates\product\view\pricedifference.phtml and this file reference in app\design\frontend\ThemeName_CompanyName\Magento_Theme\layout\catalog_product_view.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-right" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
 <referenceContainer name="content">
            <container name="product.top.wrap" htmlClass="row" htmlTag="div">
                <container name="product.top">
                    <container name="product.info.left" htmlClass="col-sm-5" htmlTag="div">

                        <block class="Vendor\Module\Block\Template" name="product.info.pricedifference" template="Magento_Catalog::product/view/pricedifference.phtml" />
                    </container>
                    <container name="product.info.middle" htmlClass="col-sm-7" after="product.info.left" htmlTag="div" />
                </container>
            </container>
            <container name="product.bottom" />
        </referenceContainer>
</page>

How can override pricedifference.phtm into my custom module in app\code\vendor_module or add new block after exact this block?

Was it helpful?

Solution

To add a new block after product.info.pricedifference block.

In catalog_product_view.xml in your module add

<referenceContainer name="product.info.left">
    <block class="Vendor\Module\Block\FileName" 
           name="product.info.custom" 
           after="product.info.pricedifference"
           template="Vendor_Module::custom.phtml">
    </block>
</referenceContainer>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top