Add Custom Layout Handles (e.g. Parent Categories)

If you ever need custom layout handles in your local.xml, it’s fairly simple. In this example, the observer method will make a new handle for categories that have children or not, but you can just modify the method to make whatever handle you desire. (I realized after creating this there’s already a handler for anchored categories with no subcategories,catalog_category_layered_nochildren)

First, add this to your config.xml in yourcustommodule:


Then add this method to your observer:

class YourPackage_YourCustomTheme_Model_Observer extends CLS_Core_Model_Abstract
    public function addHandles($observer) {
        $category = Mage::registry('current_category');
        if ($category instanceof Mage_Catalog_Model_Category) {
            $update = Mage::getSingleton('core/layout')->getUpdate();
            $fertilility = (count($category->getChildrenCategories()->getData())) ? 'parent' : 'nochildren';
            $update->addHandle('catalog_category_' . $fertilility);
        return $this;

Share it


Related Posts

Google and Yahoo Have New Requirements for Email Senders

What ROAS Really Means

Everything You Need to Know About Updating to Google Analytics 4

Contact Us