How To Set Dynamic Variable in CMS Content


public function setVariableforCMSBlock($BlockId,$VariableArray=""){

	if(!$blockId){
		return;
	}
	$block = Mage::getModel('cms/block')
		->setStoreId(Mage::app()->getStore()->getId())
		->load($blockId);
	$filter = Mage::getModel('cms/template_filter');
	$filter->setVariables($array);
	return $filter->filter($block->getContent());
	
}

use of function 
$test['test1'] = 'test1';
$test['test2'] = 'test2';

Mage::helper('example')->setVariableforCMSBlock('testCmsBlockId',$test);

you can set content in cms block like

Hello this is {{var test1}} and this is another {{var test2}}

OUTPUT :: Hello this is test1 and this is another test2

Advertisements