I've created a Layout Handle, which is updated by an observer. When the conditions are true (so that the handle is applied) that handle remains regardless of whether it should pass the test again.

My code is as follows

class Karl_CustomHandles_Model_Observer
public function addCustomHandles($observer){

    //Need + Works
    $update = Mage::getSingleton("core/layout")->getUpdate();
    $currentCategory = Mage::registry("current_category");

    if (!$currentCategory instanceof Mage_Catalog_Model_Category) {

    $defaultCategory = Mage::getModel('catalog/category')->load(2);
    $isChild = false;

    Mage::log($defaultCategory->getChildren() . " - excerpt end.");

    foreach(explode(",", $defaultCategory->getChildren()) as $child) {

        if ($child == $currentCategory->getId()) {
            $isChild = true;


    //Not works
    //Seems to apply the layouthandle to every page
    $allHandles = $update->getHandles();

    if ($isChild == true) {
        foreach ($allHandles as $singleHandle){
  • Bare in mind some of the code is a mess, attempting different solutions – ol'bob dole Jan 26 '17 at 12:54

This actually worked fine, the main issue was debugging in a phtml block - which was getting cached.

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.