1

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.

1 Answer 1

1

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

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

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.