i need to add div's in case of products special price in magento\module-catalog\view\frontend\templates\product\list.phtml

I'm ovverriding that file in my theme.

I may use e.g., to check for a special price, the same method used in magento\module-catalog\view\base\templates\product\price\final_price.phtml

<?php if ($block->hasSpecialPrice()): ?>
<?php endif; ?>

but I don't know how to call it because of different $block. How can i do it? Thanks.

1 Answer 1


Try like this. (How we can call any block function in any phtml?)

For ex your block class is

namespace Company\Helloworld\Block;
use Magento\Framework\View\Element\Template;

class Main extends Template
    public function getMyCustomMethod()
        return '<b>MyCustomMethod</b>';

then in any phtml file you can use following code to get method of this block.

$blockObj= $block->getLayout()->createBlock('Company\Helloworld\Block\Main');
echo $blockObj->getMyCustomMethod();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.