Magento Programmatically create a cms static block

Posted by Damodar Bashyal on May 10, 2013

 

You can easily create a static block in magento programmatically. Useful when you need to upload a bunch of blocks from csv. Here I haven't created a parser but just a simple code to save a block.

My file path: /magento/static-block.php

<?php
include_once 'app/Mage.php';
umask(0);
Mage::app("default");

error_reporting(E_ALL);

//Create Static Block
$staticBlock = array(
                'title' => 'My Test Block',
                'identifier' => 'my-test-block',
                'content' => 'Lorem ipsum dolor sit, amen hte gulocse',
                'is_active' => 1,
                'stores' => array(Mage_Core_Model_App::ADMIN_STORE_ID)
                );

Mage::getModel('cms/block')->setData($staticBlock)->save();

Hopefully it works for you too!!!

 
not published on website


QR Code: Magento Programmatically create a cms static block