tags:

views:

169

answers:

1

Hi,

I wonder how to check that pariticular CMS block is active or not.

So far i have found that CMS block are Mage_Cms_Block_Block class that inherits from Mage_Cms_Block_Abstract class

Mage::log(get_class(Mage::app()->getLayout()->createBlock('cms/block')->setBlockId('promo_space')

Neither of the two class have method that would check weather the block is active or not. How do i do it?

Thank's

A: 

Hi

Got this myself

I created a method isActive(Identifiere, Value) in helper "Block" in the Mage/Cms local Module.

This is how the method looks

public function isActive($attribute, $value){

    $col = Mage::getModel('cms/block')->getCollection();
    $col->addFieldToFilter($attribute, $value);
    $item = $col->getFirstItem();
    $id = $item->getData('is_active');

    if($id == 1){
        return true;
    }else{
        return false;
    }

}

parameter $attribute is table(cms-block) field such us 'indetifier' or 'title' and value can be the name of the static block or identifier itself. Both used to filter down the particular static block you are interested in

Here is how i call the helper

if(Mage::helper('cms/block')->isActive('identifier','promo_space')){ //do that }

I have also updated the config.xml file for Cms block to read my new helper and the method.

I hope its usefull

latvian