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:
<?php // Data set: $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: Mage::getModel('cms/block')->setData($data)->save(); } ?>
The only thing you need to do is fill the data array with the proper content and you’re all set!