For a single category:
You can change the layout for the single category. To do this, go to the categorie in the backend, open the tab Custom Layout
and choose "2 columns with left bar" in Page Layout
dropdown.
Implementing an observer
I think listening on core_block_abstract_to_html_before
might be a good idea. Check wether the block is root
. If it is a category, the category can be found in Mage::registry('current_category');
. Then you check for hasChildren()
and if it has, set the Template for the root block.
I'm not sure whether this is enough. Maybe you need to change the update handle too.
Implementation
Observer.php
public function coreBlockAbstractToHtmlBefore(Varien_Event_Observer $observer)
{
/* @var $block Mage_Core_Block_Template */
$block = $observer->getBlock();
if($block->getNameInLayout() == 'root') {
/* lvar $category Mage_Catalog_Model_Category */
if(($category = Mage::registry('current_category')) && $category instanceof Mage_Catalog_Model_Category) {
if(!$category->hasChildren()) {
$block->setTemplate('page/2columns-left.phtml');
}
}
}
}
config.xml
<config>
<frontend>
<events>
<core_block_abstract_to_html_before>
<observers>
<namespace_mymodule>
<type>model</type>
<class>Namespace_MyModule_Model_Observer</class>
<method>coreBlockAbstractToHtmlBefore</method>
</namespace_mymodule>
</observers>
</core_block_abstract_to_html_before>
</events>
</frontend>
</config>
1column
layout any more, its a2col-left
layout. Why not just change the root template of your categories that need this layout? You could do some block manipulation fairly easily with XML - but it goes a bit against the point of having a2col-left
layout if you are putting a left col in your1column
layout.