Ways to call Blocks within Magento: createBlock vs Layout xml file
Posted
by N. B.
on Stack Overflow
See other posts from Stack Overflow
or by N. B.
Published on 2010-04-26T19:07:58Z
Indexed on
2010/04/26
19:13 UTC
Read the original article
Hit count: 309
magento
|zend-framework
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!
© Stack Overflow or respective owner