Monday, March 30, 2015

Generate static block dropdown in System Configuration in Magento

>    First you need to create the system configuration menu. You'll find many tutorial to create system configuration menu. So, in your system.xml you need add a Source Model like "module/system_config_source_cms_block". Now create a directory in your module: YoureModule/Model/System/Config/Source/Cms/Block.php

Now your Block.php looks like below :

class CompanyName_YourModule_Model_System_Config_Source_Cms_Block

    protected $_options;

    public function toOptionArray()
        if (!$this->_options) {

$collection = Mage::getModel('cms/block')->getCollection();
$staticBlock = array(''=>'-- Select Static Block --');
foreach($collection as $block){
$staticBlock[$block->getIdentifier()] = $block->getTitle();

            $this->_options = $staticBlock;
        return $this->_options;


Refresh cache to see changes.