How to create CMS Blocks from Sql Installable Script in Magento

magento

In Magento we can create CMS Blocks from Admin side but for the custom Modules we can create CMS Blocks from our custom Module Installer Script.
Script will create CMS Blocks and then add a dummy content into it.
Please check below code to create CMS Blocks from custom module Installable Script.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Example for Creating CMS Block from Instalable Module</title>
</head>
<body>
<?php

$staticBlocks = array(
		      array(
				'title' => 'My Custom Block Title',
				'identifier' => 'my_block_identifier',
				'content' => 'My Block Content',
				'is_active' => 1,
				'stores' => array(0)
			),
			array(
				'title' => 'My Custom Block Title 2',
				'identifier' => 'my_block_identifier_2',
				'content' => 'My Block Content 2',
				'is_active' => 1,
				'stores' => array(0)
			),
		);
foreach($staticBlocks as $staticBlock)
Mage::getModel('cms/block')->setData($staticBlock)->save();
?>
</body>
</html>
Posted in Uncategorized