Search code examples
magentoeventsobservers

Change theme based on param url


I would like to know if I can change the theme based on url parameter (or if it's too late) and if it is possible which is the right event to observe
I have only found a guy who was talking about observing controller_action_predispatch but with this event I can't still access to the parameters url (based on this answer https://stackoverflow.com/a/19214765/1139052)


Solution

  • Yes, you could do that a number of different ways. That answer is not saying the URL params are inaccessible in the controller_action_predispatch event, however you might want to do it during an event like controller_action_layout_load_before instead and create custom layout handles from your param value. You can get them in your observer like this:

    public function getExampleParam(Varien_Event_Observer $observer)
    {
        $request = $observer->getControllerAction()->getRequest();
        $param = $request->getParam('example');
        return $this;
    }