Ever been in the situation where your next update for your clients’ Magento installation requires adding a new static block? Don’t feel like logging in on the live site and doing it manually? Just add this little code snippet in your setup- or update-script to create that static block on the fly:
$data = array(
'title' => 'Title',
'identifier' => 'identifier',
'stores' => array(0), // Array with store ID's
'content' => '<p>Some HTML content for example</p>',
'is_active' => 1
// Check if static block already exists:
$block = Mage::app()->getLayout()->createBlock('cms/block')->setBlockId($data['identifier']);
if($block->getId() == false)
// Create static block:
The only thing you need to do is fill the data array with the proper content and you’re all set!
Visitors give this article an average rating of 4.3 out of 5.
How would you rate this article?
★ ★ ★ ★ ★