2
<update handle="page_one_column" />

These both set the template to 1page. Is there any reason to use one over the other?

<reference name="root">
  <action method="setTemplate"><template>page/1column.phtml</template></action>
</reference>

I have noticed that both of these seem to have the same effect (making the page use the 1column.phtml template) but I'm sure there are subtle differences that only a Magento expert would know about. Is there any reason to use one over the other? I like the flexibility of using the update handle, but it seems like it could have unintended repercussions.

The first question that comes to mind is: does the page_one_column handle override the page_two_columns_left handle that is already there? Could this cause the page to have both handles?

Edit[Clarification]: I understand that <page_one_column> is a layout handle, and it can be "applied" by calling <update handle="page_one_column" />. What I don't understand (and want to know) is if this can cause any negative side-effects. I myself can't think of any edge cases where this might break something, but it seems like they could exist. I can't really know for sure without digging deep into the code and trying to break stuff.

1

To understand the purpose of <update handle="some_name"> you can look at following magento file:

/app/design/frontend/base/default/layout/catalog_msrp.xml

you can create your own handle

<my_handle_blabla>
    <!-- some layout -->
</my_handle_blabla>

Then you can add your handle anywhere <update handle="my_handle_blabla" /> It's like echo $property

  • This is correct and useful information, but doesn't quite answer my question. I have clarified the question. – Eric Seastrand Apr 27 '15 at 16:48
1

Yes, you can use either handle or reference root and set the template yourself.

Both of them do the exact same thing. A layout (e.g. catalog_product_view) can include as many as needed. It won't break anything.


Look at handle is a proper way to practice code re-use (or a function call for lack of better words).

For example, you have your own module that render 2 different routes

module/controller/action1
module/controller/action2

So you have 2 layouts accordingly

module_controller_action1
module_controller_action2

In both layout, says you have to include CSS/JS for both of these pages

You can do it this way in your layout file

<module_controller_action1>
    <reference name="head">
        <action method="addItem">
            <type>skin_css</type>
            <name>css/module/style.css</name>
            <params/>
        </action>
        <action method="addItem">
            <type>skin_js</type>
            <name>js/module/script.js</name>
        </action>
    </reference>
    <reference name="content">
        <!-- DECLARE BLOCK -->
    </reference>
</module_controller_action1>

<module_controller_action2>
    <reference name="head">
        <action method="addItem">
            <type>skin_css</type>
            <name>css/module/style.css</name>
            <params/>
        </action>
        <action method="addItem">
            <type>skin_js</type>
            <name>js/module/script.js</name>
        </action>
    </reference>
    <reference name="content">
        <!-- DECLARE BLOCK -->
    </reference>
</module_controller_action2>

Or you can use update handle mechanism to make it neater this way

<module_controller_assets>
    <reference name="head">
        <action method="addItem">
            <type>skin_css</type>
            <name>css/module/style.css</name>
            <params/>
        </action>
        <action method="addItem">
            <type>skin_js</type>
            <name>js/module/script.js</name>
        </action>
    </reference> 
</module_controller_assets>

<module_controller_action1>
    <update handle="module_controller_assets" />
    <reference name="content">
        <!-- DECLARE BLOCK -->
    </reference> 
</module_controller_action1>

<module_controller_action2>
    <update handle="module_controller_assets" />
    <reference name="content">
        <!-- DECLARE BLOCK -->
    </reference> 
</module_controller_action2>
1

Is there any reason to use one over the other

Not really as far as I know. They do the same thing. <update handle="page_one_column" /> is just shortcut that has been hard-coded in Mage_Page. See app/code/core/Mage/Page/etc/config.xml.

The setTemplate (Mage_Core_Block_Template::setTemplate) method in your example simply sets root's template to page/1column.phtml, which is configured in the config.xml file above.

Your Answer

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

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