I'm attempting to output the wishlist block as an ajax request. I've attempted to do it in the controller using
$block = $resultPage->getLayout()
->createBlock('Magento\Wishlist\Block\Customer\Wishlist','miniwishlist')
->setTemplate('Company_Module::miniwishlist.phtml')
->toHtml();
But as the block contains several child blocks and I didn't have any success in using the setChild method programmatically.
I've since created a layout file that returns the block by itself. The problem is that output contains html, head, body tags, css and javascript.
I want to return only the block and nothing else. How can I achieve that?
after.body.start
andpage.wrapper
.<html>
and<body>
are added viaroot.phtml
. Setting that page to use a new empty template (only including the code you require) instead ofroot.phtml
may work? You can see this template being set invendor/magento/magento2-base/app/etc/di.xml
line 563 (for me at least). The root template can be seen invendor/magento/module-theme/view/base/templates/root.phtml
. I don't have the time to actually try it and provide a full answer sorry, if no one answer by the time I do I will give it a try and reply with a full answer.