Magento render cms/block with widgets

You create a cms static block (cms/block) and dynamise it with widget, here an example:

1
2
3
<div class="confirmation">
       <img src="{{skin url='images/image-order.jpg'}}" alt="" />
</div>

You then render this block :

1
2
3
echo Mage::getModel('cms/block')
            ->setStoreId(Mage::app()->getStore()->getId())
            ->load(self::confirmationCmsBlockName)->render();

But the widget {{skin url=’images/image-order.jpg’}} is not executed and is display as {{skin url=’images/image-order.jpg’}}.

To execute the widget, you need to render as HTML a block and not a model

1
echo  Mage::app()->getLayout()->createBlock('cms/block')->setBlockId(self::confirmationCmsBlockName)->toHtml();

Leave a Reply