0

I am using Magento 2.3.1, I wanted to include the custom template in product listing page for all products just above the add to cart button as shown in the attachment.

enter image description here

Below is my code I tried.

<?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>
        <referenceContainer name="product_list">
            <block class="Magento\Framework\View\Element\Template" name="yousave" template="MyVendor_MyModule::yousave.phtml" after="additional" />
        </referenceContainer>
    </body>
</page>

and template is

<?php echo 'hello world'; ?>

but I am not getting proper output

10
  • product listing page ??
    – Rk Rathod
    Jun 20 '19 at 12:03
  • yes, product listing page Jun 20 '19 at 12:04
  • add wherever you want in list.phtml file <?php echo $this->getLayout()->createBlock("Magento\Framework\View\Element\Template")->setTemplate("MyVendor_MyModule::yousave.phtml")->toHtml();?> Jun 20 '19 at 12:08
  • please add your yousave.phtml file code
    – Rk Rathod
    Jun 20 '19 at 12:09
  • if i want to add above code directly into list.phtml i would have done it. but i wanted to add from external module to list.phtml Jun 20 '19 at 12:10
0

You have to call getChildHtml('yousave') ; ?> in your list.phtml

and add the below code in listing xml file.

<block class="Magento\Catalog\Block\Product\ListProduct"  name="yousave" template="Magento_Catalog::product/yousave.phtml"/>

Note: you can override the file as per your convenience.

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.