I'm trying to find a way of inserting a small form into the adminhtml sales order view page, right above the order items block, without intervening in the template file. So, basically, is there a way of doing that exclusively via layout XML?

2 Answers 2


You can replace the gift message block with your own and append the output of the original gift message block. I have not tested but it should work:

  1. Use handle adminhtml_sales_order_view
  2. Set your block into the layout which will reference order_giftmessage block
  3. In your block, overload method _prepareLayout
  4. add :

    $giftMessageBlock = $this->getLayout()->getBlock('order_giftmessage);
    $this->setData('gift_html', $giftMessageBlock->toHtml());
    $giftMessageBlock->setTemplate('YOUR TEMPLATE'); // dont forget to echo data gift_html
  5. And return parent method
  6. That's all
  • Important note: This is only possible in Magento Enterprise, in CE there is no gift_message block. Feb 15, 2015 at 0:14

If you are using Magento EE, refer to the answer of GuillaumeD, which shows an halfway elegant way to include a custom block via layout.

For Magento CE you'll have to choose the lesser of two evils, i.e. modify the rendered HTML of the order_view_info block with an observer to not replace the whole template for this block:

  • Observe the event core_block_abstract_to_html_after
  • In the observer, check if the block class is Mage_Adminhtml_Block_Sales_Order_View_Tab_Info
  • if so, inject $customBlock->toHtml() into the result. You can try to find the right position with str_replace or preg_replace but I prefer using DOM manipulation:

    • Find the shipping information div with the following XPath:

    • Insert new content after this.

What you should know about the core_block_abstract_to_html_after event is, that you need to copy the output at the very beginning, otherwise it gets lost as soon as another block is rendered because they will share the same transport object:

$html = $observer->getTransport()->getHtml(); // should be the first statement
// now you can do what you want, create other blocks, modifiy $html ...
$observer->getTransport()->setHtml($html); // should be the last statement

Source: http://www.schmengler-se.de/en/2015/01/magento-block-inhalt-verschwindet-nach-core_block_to_html_after-event/

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.