Take the 2-minute tour ×
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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>
share|improve this answer
    
Works like charm! +1 –  balanv Mar 8 at 13:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.