1

I'm trying to update the product widget to show some custom product data like that

 <?= $block->getChildBlock('name-of-block')->setProduct($_item)->toHtml() ?>

while this code works fine on list.phtml in the CatalogWidget's grid.phtml it cannot set the product

2 Answers2

2

Issue that getChildBlock('name-of-block').

The .phtml or file where you have called <?= $block->getChildBlock('name-of-block')->setProduct($_item)->toHtml() ?> that block does not have any child block of name 'name-of-block'.

Ensure that name-of-block child Block exits for that current block.

<?php if($block->getChildBlock('name-of-block')):?>
<?= $block->getChildBlock('name-of-block')->setProduct($_item)->toHtml() ?>
<?php endif;?>
Amit Bera
  • 77,456
  • 20
  • 123
  • 237
0

Actually, the problem was that I had to get the layout first, so the working code was

<?= $block->getLayout()->getChildBlock('name-of-block')->setProduct($_item)->toHtml() ?>