Take the 2-minute tour ×
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It's 100% free, no registration required.

I am using one step checkout and shipping_method.phtml resposible for showing the shipping methods.so now i have 2 more modules which both have shipping_method.phtml each.so i need to show either shipping_method.phtml from Module A or Module B depending on the shipping country.

so i wanted to update handle called in that i will be updating the handle with module A or B depending on the condition statfication which just updates the setTemplate file either from A or B.

Please Help me how to achive this.

<a_onestepcheckout>
    <reference name="choose-shipping-method">
        <action method="setTemplate">
            <template>a/l/onestepcheckout/shipping_method.phtml</template>
        </action>
    </reference>
</a_onestepcheckout>

<b_onestepcheckout>
    <reference name="choose-shipping-method">
        <action method="setTemplate">
            <template>b/l/onestepcheckout/shipping_method.phtml</template>
        </action>
    </reference>
</b_onestepcheckout>

// either a_onestepcheckout or b_onestepcheckout depending on condition
<onestepcheckout_index_index>
    <update handle="a_onestepcheckout" /> or <update handle="b_onestepcheckout" />
</onestepcheckout_index_index>
share|improve this question

1 Answer 1

up vote 4 down vote accepted

I don't think you can load a conditional layout handle from the xml.
You will have to do this in an observer.

Use the event controller_action_layout_load_before.
Something like this:

public function addSomeHandle($observer) {
    $action = $observer->getEvent()->getAction();
    $actionName = $action->getFullActionName();
    if ($actionName == 'onestepcheckout_index_index') { //if on your desired page
         $layout = $observer->getEvent()->getLayout();
         if (CONDITION GOES HERE) {
             $layout->getUpdate()->addHandle('a_onestepcheckout');
         }
         else {
             $layout->getUpdate()->addHandle('b_onestepcheckout');
         }
    }
}
share|improve this answer
    
thanks for answer.i tried this but i am getting error Fatal error: Call to undefined method Mage_Core_Model_Layout::addHandle() in Observer.php –  Pradeep Sanku Apr 30 at 11:16
    
@pradeepsanku. Oups. Sorry about that. I forgot an ->getUpdate() in the code. I've updated the code, try it now. –  Marius Apr 30 at 11:26
    
thanks it had worked for me.thanks a lot. –  Pradeep Sanku Apr 30 at 11:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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