1

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 '14 at 12:56
0

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)
{

$fullAction=$observer->getEvent()->getFullActionName()
if($fullAction=='catalog_category_view'):

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

$children = Mage::getModel('catalog/category')->getCategories($currentCategoryId);
if(count(count($children)>0)){
       $observer->getEvent()->getLayout()->getUpdate()
       ->addHandle('cat_has_child_cat');
}else{
      $observer->getEvent()->getLayout()->getUpdate()
       ->addHandle('cat_has_no_child_cat');
}
endif;
}

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>
        </reference>
    </cat_has_child_cat>


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

</layout>
| improve this answer | |

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.