I am wondering if there is a way to customize the layout for when you are on a https page. As in creating a entire layout file or just layout statements in existing files that will only activate on https pages.

I recently ran into some problems with sharethis where I was including the non-https version that worked until we activated https urls on the site. After this the script was being blocked as it was a non-https url.

The solution that I found for this was to switch to the share this secure url which works for both. However it got me thinking if there was a way to use layouts to fix problems similar to this.

I have found you can simply use "//www.example.com" to automatically pull the current http/https however this doesn't work for different urls like share this.



For example if you wanted to add a block advertising your sever security only when you are in https. Would this need to be done in a php block or could it be done via xml layouts.

1 Answer 1


For this case, we can add new layout handler on basic of http/https at event controller_action_layout_load_before.

Event: controller_action_layout_load_before

Condition: Mage::app()->getRequest()->isSecure() is check page with https or http.

So , i am start an observer on basic of this condition which is add new
handler on current layout

When page with

  • https then add handler my_current_page_is_https
  • http then add handler my_current_page_is_http

Observer code:

class [ModuleNameSpace]_[ModuleName]_Model_Observe{ 
     * Before load layout event handler
     * @param Varien_Event_Observer $observer
    public function beforeLoadLayout($observer)
        $isSecure =  Mage::app()->getRequest()->isSecure();

           ->addHandle('my_current_page_is_' . ($isSecure ? 'https' : 'http'));


Config.xml code;


Now on this of this handler,you can add a new block to layout and a new phtml.

Suppose, you want to change the layout all https page to 1-column then you can try this.

    <reference name="root">
            <action method="setTemplate"><template>page/1column.phtml</template></action>
            <!-- Mark root page block that template is applied -->
            <action method="setIsHandle"><applied>1</applied></action>
            <action method="setLayoutCode"><name>one_column</name></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.