Magento – Can you set a template for every action within a controller

controllerslayoutmagento-1.9template

For instance I have a module My/Module (my_module) with a controller RenderController.php which has an action layoutAction. Is there a way that I can set a template for every action within the RenderController controller without having to do it for each individual "page" using layout xml.

I essentially want something like this:

<default>
        <reference name="root">
            <action method="setTemplate"><template>page/1column.phtml</template></action>
        </reference>
</default>

but I don't want that template to be assigned for EVERY page in my theme, but only for those within my module, or even the specific controller (RenderController.php) within that module.

Best Answer

If you want to change the template of the root reference, you can try with something like :

public function yourSpecialAction() {

    $this->loadLayout();
    $this->getLayout()->getBlock('root')->setTemplate('path/to/the/template/you/want'));
    // Do your process
    $this->renderLayout();
}
Related Topic