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

I have created a file called “myblock.phtml” in frontenddefaultdefaultlayoutmytemplate .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 thoughts on “How to disable custom layouts in magento based on a custom module state?”

  1. 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

  2. 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!


  3. //This is the code in my module’s block “Checkbox.php” .Just might be useful for others..

    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.

Leave a Reply

Your email address will not be published. Required fields are marked *