I want 1 column layout for main category and for sub-category 2 column layout, basically want to remove left side section for main category

In my phtml file code like below, want to change layout from phtml file.

$_category  = $this->getCurrentCategory();
$category = Mage::getModel('catalog/category')->load($_category->getId());
$subCategories = $category->getChildrenCategories();

if(count($subCategories) > 0) {
<action method="setTemplate"><template>onecolumns.phtml</template></action>
<action method="setTemplate"><template>2columns.phtml</template></action>

Method 1: Custom design

You can use custom layout update from the admin panel where you edit the category.

It is under "custom design"

enter image description here enter image description here

Method 2: Overrides

So you need to override the CategoryController which should be under \app\code\core\Mage\Catalog\controllers\CategoryController.php

Some example I was able to google out about how to override a controller:

Overriding controller

Now you need to take a look on the viewAction() in the CategoryController

     * Category view action
    public function viewAction()
        if ($category = $this->_initCatagory()) {
            $design = Mage::getSingleton('catalog/design');
            $settings = $design->getDesignSettings($category);

            // apply custom design
            if ($settings->getCustomDesign()) {


            $update = $this->getLayout()->getUpdate();

            if (!$category->hasChildren()) {

            $update->addHandle('CATEGORY_' . $category->getId());

            // apply custom layout update once layout is loaded
            if ($layoutUpdates = $settings->getLayoutUpdates()) {
                if (is_array($layoutUpdates)) {
                    foreach($layoutUpdates as $layoutUpdate) {

            // apply custom layout (page) template once the blocks are generated
            if ($settings->getPageLayout()) {

            if ($root = $this->getLayout()->getBlock('root')) {
                $root->addBodyClass('categorypath-' . $category->getUrlPath())
                    ->addBodyClass('category-' . $category->getUrlKey());

        elseif (!$this->getResponse()->isRedirect()) {

Now you should replace the logic with your own adding your layout handles depending on the results.

You can access the current category within the function :

$category = $this->_initCatagory()
  • than for every category it will follow that layout, want to differentiate two main category and sub-category – Mandip Darji Aug 6 '18 at 10:05
  • Why would it ? It will affect only the category you will specify, so you specify default layout 2 columns for all categories, and update the configuration for the lvl1 categories with the custom design – Gosu Przmak Aug 6 '18 at 10:08
  • than i have to set for every category Custom Layout Update ? – Mandip Darji Aug 6 '18 at 10:10
  • Well that's one way ofc you can edit or override the block/controller and add some custom logic there. – Gosu Przmak Aug 6 '18 at 10:13
  • Well that's one way ofc you can edit or override the block/controller and add some custom logic there. – Gosu Przmak How ?????? – Mandip Darji Aug 6 '18 at 10:20

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.