Search code examples
magentomagento-1.9

Load Magento module template


For a Magento module I need to load template file and let it replace the complete page. It is a XML file (but could also be any content whatsoever). Generally speaking when

MYNS_MYMODULE_controllernameController is triggered and calls fooAction() I need to be able to display a clean site with the content from my template file.

Please let me know where to place the template file and how to tell Magento to load this file as a root template without anything else around.

Edit, to clarify it more:

For http://domain.tld/modulename/controller/action/

Where do I have to place template files and how should I reference them?


Solution

  • You could do it like this

      $this->loadLayout()->getLayout()->getBlock('root')->setTemplate('page/1column.phtml');
      $this->renderLayout();
    

    or to set a custom response

     //$file = myfile or html
    
     $this->getResponse()->setBody($file);
     $this->renderLayout();
    

    Ideally your template should sit in /app/design/frontend/mypackage/mytheme/template/mytemplate.phtml