5

I am going through this link to understand Layout handles. Here I have seen that the layout handles are in the form of [module_front_name]_[controller_name]_[action_name]. So, for example the layout handle for "Contact us" page is contacts_index_index, which calls the "indexAction" method available in "indexController" controller of "Contacts" module.

Later, I have seen other layout handles like:

  • page_empty
  • page_one_column
  • page_two_columns_left
  • page_two_columns_right
  • page_three_columns

in "page.xml" layout file. (which are also in config.xml file of "page" module)

The above Layout handles are not in the form of [module_front_name]_[controller_name]_[action_name]. Then what are they?

My understanding is not clear on both the types of Layout handles. (Are there any other Layout handle types?)

Please explain

6

Layout handles are somehow independent from the actions.
You can declare any layout handle you want as long as it is a valid XML tag.
Each action loads by default the handle [module_front_name]_[controller_name]_[action_name] but you can load any layout handle either in the controller, see an example here: Mage_Catalog_CategoryController::viewAction()

$update->addHandle('catalog_category_layered_nochildren'); 

or you can load a handle inside an other handle using

<update handle="handle_here" />

See an example in the newsletter.xml layout file, inside the tag newsletter_manage_index.

  • So, if we don't want to load a layout handle manually then we need to follow this format: [module_front_name]_[controller_name]_[action_name]... right? (just confirming, as I am bit confused right now) – Mr_Green Sep 12 '13 at 6:37
  • @Mr_Green. Yes. That layout will be loaded automatically for a page that has the url [module_front_name]/[controller_name]/[action_name]. If you want something available in that page, put it inside the layout handle [module_front_name]_[controller_name]_[action_name] – Marius Sep 12 '13 at 6:45
  • ok I am clear with your explanation. Thanks.. Now I have doubt like: why a controllers action method add's the layout handle explicitly or implicitly, when we are gathering the complete layout xml file in config.xml of that same module? if you can't understand my question then please come to this chat room if you are free. I will not take much time of you. – Mr_Green Sep 12 '13 at 6:51
4

In the next article the author digs deeper into layouts including creating your own layout handles.

http://magebase.com/magento-tutorials/digging-deeper-into-magentos-layout-xml-part-2/

Scroll about halfway down and there's a good explanation!

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.