adminhtml – How to Add Block Above Adminhtml Grid

adminhtmlblocksgrid

I've seen quite a lot of modules where they'll display a grid, but above that will be a block (sometimes an encouragement to upgrade, sometimes some additional information for the user).

I would like to add an Adminhtml form there.

The form is complete, and the grid is complete, but I can't seem to find any sort of hook to include the form in the grid.

I've already tried overriding the getMainButtonsHtml() method, but that seems to put the block underneath the filters. Ideally it needs to be above the filters. Is there a similar function for the HTML above the filters?

My other option would be to create an additional block that gets initialised in the tab, this one would include the form and the grid; so instead of adding the form to the grid, I'd add both the form and the grid to a container element.

Is there another (cleaner) way to do this?

Best Answer

I was able to override the block's _toHtml method and include the block:

/**
 * Override this method in descendants to produce html
 *
 * @return string
 */
protected function _toHtml()
{
    $html = $this->getLayout()->createBlock('mymoudule/adminhtml_myblock')->toHtml() . '<br />';
    $html .= parent::_toHtml();

    return $html;
}