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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<?php // Data: $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!
Visitors give this article an average rating of 4.3 out of 5.
How would you rate this article?
★ ★ ★ ★ ★