How to disable custom layouts in magento based on a custom module state?

927 views Asked by At

I have created a file called "myblock.phtml" in frontend\default\default\layout\mytemplate .It simply displays a "check " button which in turns calls a custom module's controller url.The question is,I want to stop displaying that button(i.e;the myblock.html template ) whenever that custom module is disabled since it doesnt make sense without the enabling the module.Any way to tweak within the module's config.xml??

3

There are 3 answers

1
PraveenMax On BEST ANSWER

//This is the code in my module's block "Checkbox.php" .Just might be useful for others..

<?php
class Mypackage_Myextension_Block_Checkbox extends Mage_Core_Block_Template {

    //echos a text based on module state
    protected function checkstate() {

        $modules = Mage::getConfig()->getNode('modules')->children();
        $modulesArray = (array)$modules;

                             //my module name
        if($modulesArray['Mypackage_Myextension']->is('active')) {
            echo "Mypackage_Myextension is active.";
        } 
        else {
            echo "Mypackage_Myextension is not active.";
        }
    }
}

?>

Thus,when i disable the module (System->Advanced->Disable Module),the block contents is not shown.

0
Anton S On

All templates should go through a block and in block you can make additional checks or let the default magento feature disable block output when your extension is disabled from administration page

3
Joe Mastey On

To expand on Anton's answer, create a custom block class that does something like this:

class Mypackage_Myextension_Block_Checkbox extends Mage_Core_Block_Template {

    protected function _toHtml() {
        if(!$this->checkIfModuleIsEnabled()) {
            return "";
        }
        return parent::_toHtml();
    }
}

Hope that helps!

Thanks, Joe