I'm trying to add a block (with template) in category page before products prices block (<?php /* @escapeNotVerified */ echo $block->getProductPrice($_product) ?> in list.phtml).

I've created catalog_category_view.xml layout:

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <referenceBlock name="product.price.render.default">
            <block name="w1.block" as="w1.block" class="WaPoNe\HelloWorld\Block\Product\ListProductW1" template="WaPoNe_HelloWorld::product/price/discount.phtml" />

my WaPoNe\HelloWorld\Block\Product\ListProductW1 block file:

namespace WaPoNe\HelloWorld\Block\Product;

class ListProductW1 extends \Magento\Framework\View\Element\Template
    public function getDiscountLabel()
        return "Discount Label";

and a simple template file (product/price/discount.phtml):

echo $block->getDiscountLabel();

This doesn't not work but if I change <referenceBlock name="product.price.render.default"> with <referenceContainer name="content">, for example, it works.

What is wrong?

  • You have to do it with calling block file inside template. May be i am not aware, No way through xml file. – Rakesh Jesadiya Dec 1 '16 at 13:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.