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

1
0

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

Your Answer

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

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