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 Answers 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;?>

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() ?>

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.