I have lots of categories and sub categories for them. For example,

Car is a category Benz, Audi, BMW are its sub categories.

So if the user is in Car category page it will show a small description of Car with a photo, also list all the sub categories of Car after that. Important thing is that this page is two column. In other words, this page have sidebar.

Now if a user comes to Benz category, it shouldn't have that side bar. In other words it should be full width template.

How to achieve this requirement.?

Note : I don't want to set template manually for that category through admin panel. I want to do this automatically. Like if the category don't have any sub category, then full width template should load.

  • Jithesh Kt, are you want to use 1column layout when category did have subcat and or use two col lay when cat have childa cat
    – Amit Bera
    Nov 1, 2014 at 12:56

1 Answer 1


Create an event on controller_action_layout_load_before event
Study Basic magento event observer http://www.solvingmagento.com/events-and-observers-a-magento-tutorial/

on put an condition current fullaction and

add a layouts

public function beforeLoadLayout($observer)


$currentCategoryId=  Mage::getSingleton('catalog/layer')->getCurrentCategory()->getId();

$children = Mage::getModel('catalog/category')->getCategories($currentCategoryId);

Create local.xml at your lyaout file add below code and set template according to it

<?xml version="1.0"?>
<layout version="0.1.0">
    <cat_has_child_cat translate="label">
        <!-- Mage_Catalog -->
        <reference name="root">
            <action method="setTemplate"><template>page/1column.phtml</template></action>

    <cat_has_no_child_cat translate="label">
        <!-- Mage_Catalog -->
        <reference name="root">
            <action method="setTemplate"><template>page/2columns-right.phtml</template></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.