Magento 1.8 – How to Load Custom Block from Overridden Admin Controller

blocksmagento-1.8template

I have override an adminhtml controller Mage_Adminhtml_System_ConfigController.
I am trying to load a .phtml file from one of my Custom module as like below

$block = Mage::app()->getLayout()->createBlock('custommodule/blockname')->setTemplate('custommodule/file.phtml');

$html = $block->getHtml();

But since i am in an Admin controller, the system tries to setTemplate in under

adminhtml/default/default/template/custommodule/file.phtml

But the file i want to load is under

frontend/default/default/template/custommodule/file.phtml

The system throws error like, the template path does not exists.
I am aware that this is happening since we are in an admin controller, and
the system tries to load the admin layout file. Trying to see the possibility
of doing this.

Suggest me a solution.

Note : This code works well when i call it from a front end controller.

Thanks

Best Answer

Try to set frontend area for your block before setting template

$block = Mage::app()->getLayout()
    ->createBlock('custommodule/blockname')
    ->setData('area','frontend')
    ->setTemplate('custommodule/file.phtml');

The same you can also do in layout xml file

<block type="custommodule/blockname" template="custommodule/file.phtml">
    <action method="setData">
        <key>area</key>
        <value>frontend</value>
    </action>
</block>
Related Topic