I am calling below code in my addtocart.phtml to get cart item data

<?php echo $this->getLayout()->createBlock("Magento\Checkout\Block\Cart\Item\Renderer")->setTemplate("Magento_Checkout::cart/item/default_custom.phtml")->toHtml(); ?>

but it returns null array.Please let me know why this code is not working.


Use $block instead of $this. For your case:

<?= $block->getLayout()->createBlock("Magento\Checkout\Block\Cart\Item\Renderer")->setTemplate("Magento_Checkout::cart/item/default_custom.phtml")->toHtml(); ?>

Make sure you pass available data to that block for display

  • ,still not working.same result. – akgola Nov 15 '19 at 4:47

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.