2

For a bunch of reasons, I'd like to be able to switch a CMS page's template based on some PHP.

In config.xml:

<frontend>
        <events>
            <controller_action_layout_load_before>
                <observers>
                    <Ecomm_Search_set_root_template>
                        <type>singleton</type>
                        <class>Ecomm_Search/observer</class>
                        <method>setRootTemplate</method>
                    </Ecomm_Search_set_root_template>
                </observers>
            </controller_action_layout_load_before>
        </events>
    </frontend>

in local.xml:

<?xml version="1.0" encoding="UTF-8"?>
<layout version="0.1.0">
    <set_root_template>
        <reference name="root">
             <action method="setTemplate"><template>page/new_template.phtml</template></action>
        </reference>
    </set_root_template>
</layout>

In Observer.php:

public function setRootTemplate(Varien_Event_Observer $observer) {
    //some other logic goes here
    $layout = $observer->getEvent()->getLayout()->getUpdate();
    $layout->addHandle('set_root_template');
    return $this;
}

Everything is running/working as expected, but the template doesn't switch. what am I missing here? is there some other thing overriding what I do because it runs last?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.