Object-specific Layout Update Handles

Object-specific Layout Update Handles

Object-specific Layout Update Handles

Every HTTP request in Magento results with a few layout handles which can be used to customize layout of desired pages. If you ever tried to dump layout handles in Magento, you would see many of them. These handles are calculated differently, based on different variables. Depending on whether the user is logged in or not, Magento uses customer_logged_in and customer_logged_out handles. Different stores have also different layout updates (e.g. STORE_default, STORE_cars, STORE_fashion…). Themes have their own layout handles, e.g. THEME_frontend_default_default, THEME_frontend_enterprise_default. You might noticed that Magento uses this functionality to create unique layout handles for different categories (e.g. CATEGORY_96, CATEGORY_35) and products (e.g. PRODUCT_22735, PRODUCT_225). Handle will be composed of string concatenated to object’s id (like OUR_COOL_OBJECT_535, OUR_COOL_OBJECT_863). 1. Create Observer In order to add handle to Magento’s layout update object before it’s too late, we have to observe controller_action_layout_load_before event.


2. Add Handle Now we have to calculate layout update handle and add it to the layout update object.

            $id = Mage::app()->getRequest()->getParam('id');
            /* or */
            if($ourCoolObject = Mage::registry('our_cool_object'))
                $id = $ourCoolObject->getId();

Info: Source : http://inchoo.net/ecommerce/magento/custom-layout-update-handles/

  • Share on Facebook
  • Share on Twitter
  • Share on LinkedIn
  • Youtube

leave a comment