I have a controller and want to define or render custom layout for different parameters passed from user to it:

    public function myactionAction() {


            $params = $this->getRequest()->getParams();

            if(array_key_exists('customaction', $params)){
                     // default layout
            elseif(array_key_exists('another_subaction', $params))
                   // different layout

i tried some xml in layouts:

        <reference name="root">
        <action method="setTemplate"><template>customer/custom.phtml</template></action>

but no success, is it possible to to this is magento or i should register another controller?

1 Answer 1


Yes this is possible with Magento and you don't need a new controller.

I would consider creating an observer however that observes the controller_action_layout_load_before event.


Inside your observer method you could get the request and test the parameters before adding a handle to the layout update.

class Namespace_Mymodule_Model_Observer
    public function loadSomeLayout($observer) {
        $layout = $observer->getEvent()->getLayout();
        $param = Mage::app()->getRequest()->getParam('hello');
        if ($param == "world")

Then, in your layout xml:

        <reference name="root">
        <action method="setTemplate"><template>customer/custom.phtml</template></action>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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