Magento – Adding custom variables to Magento Static Blocks

Iโ€™ve been asked to customize the front page of a magento store. The client wanted the ability to specify a set of variables that can be used in CMS static blocks so static blocks can be a little more dynamic.

By default, the standard magento CMS static blocks donโ€™t provide access to the custom variables. so I thought I was going to have to build an extension to pass the variables in. However after a little bit of finding, I found that this functionality is available as standard in Magento, you just need to do it properly.

The way to do this is as follows. Within you template file add in the following code:

$quote = $this->getData('quote');
$identifier = Mage::getStoreConfig('qquoteadv/patches/quote_success_msg');

$filter = Mage::getModel('core/email_template_filter');
$filter->setVariables(array('quote_number' => $quote->increment_id));
$block = $this->getLayout()->createBlock('cms/block')->setBlockId($identifier);

$html = $filter->filter($block->toHtml());

This will then display the static block with your variables expanded to values youโ€™ve set.

then you can use this variable in cms block {{var quote_number}}

Leave a Comment