Tuesday, 11 June 2013

Adding a CMS static block into nearly any page (example: cms block on contact us page)

Easier than it sounds, this. It only works with phtml files, I think.

1) Go to your backend, cms -> static blocks. Create a block with the content you wish to display and the important bit, NOTE the Identifier, that's the key we use to call the block.
In this example I created a block and called it "contactusblock".

2) Open the phtml file, in this case app\design\frontend\<yourname>\default\template\contacts\form.phtml

Add:


<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('contactusblock')->toHtml() ?>


anywhere you like in the phtml file.

Clear any caches, etc. 

Good to go.