开发者

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

开发者 https://www.devze.com 2023-02-09 00:57 出处:网络
I have created a file called \"myblock.phtml\" in frontend\\default\\default\\layout\\mytemplate .It simply displays a \"check \" 开发者_如何学JAVAbutton which in turns calls a custom module\'s contro

I have created a file called "myblock.phtml" in frontend\default\default\layout\mytemplate .It simply displays a "check " 开发者_如何学JAVAbutton 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??


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


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


//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

精彩评论

暂无评论...
验证码 换一张
取 消