Question

Im currently trying to simply add a block to a custom Adminhtml module. i am able to display the content of the block but it renders right at the top of the page with a grey background, and then the standard magento layout with the design and menu renders directly underneath it.

im trying to do things in the correct fashion as to learn best practises and am following books and tutorials as well as the magento core but so far have been unable to add content correctly.

so far i have :

public function indexAction()
{
    $this->loadLayout();
    $this->_setTitle();
    $main_block = new Invent_General_Block_Info();
    echo $main_block->toHtml();
    //$this->_addContent($main_block);
    $this->renderLayout();

i can see the general way to do so in the Mage Core would be something like

/**
  * Append customers block to content
  */
    $this->_addContent(
        $this->getLayout()->createBlock('adminhtml/customer', 'customer')
    );

since i have already created the block $main_block it doesnt make sense to me to ->createBlock and so im not sure what to do from here.

any assistance is appreciated as usual. thanks!

Was it helpful?

Solution

I have found an answer that solved this problem.

of course it would come from Alan Storm. Thanks Alan. the thread is found here!

so to solve this, all i did was :

create a folder in app/design/adminhtml/mythemename/info.phtml

and then in my controller action i simply did :

$this->loadLayout();
    $this->_setTitle();
 $this->_addContent($this->getLayout()->createBlock('adminhtml/template')->setTemplate('shipment/info.phtml'));
    $this->renderLayout();

and it works great.

OTHER TIPS

Use this if its a static block you created through your CMS

/**
  * Append customers block to content
  */

$this->_addContent(
  $this->getLayout()
    ->createBlock('cms/block')
    ->setBlockId('{block_name}')
    ->toHtml() 
);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top