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">
<body>
<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" />
</referenceBlock>
</body>
</page>
my WaPoNe\HelloWorld\Block\Product\ListProductW1 block file:
<?php
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):
<?php
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?