Ways to call Blocks within Magento: createBlock vs Layout xml file
- by N. B.
Context: I'm trying to include Adminhtml blocks in the frontend of the site to replace some of the user account blocks. The first thing I'm trying to do is simply display the block on the correct page. I can replace the entire page by setting the Body of the response inside the controller, but I'm having a hard time including the block in the layout xml file and then calling it within the template.
Why would I be able to create an adminhtml/sales_order_grid from Mage_Sales_OrderController using createBlock:
$this->getResponse()->setBody($this->getLayout()->createBlock('adminhtml/sales_order_grid')->toHtml());
But not from a frontend layout, using a declaration
<block type="adminhtml/sales_order_grid" name="orders_widget"/>
within app/design/frontend/default/default/layout/sales.xml
The latter produces an error without a stack trace: Fatal error: Call to a member function toHtml() on a non-object in app/code/core/Mage/Core/Model/Layout.php on line 526
Thanks for any guidance!