Creating a CMS pages and blocks in Magento is simple as navigate to Admin Panel -> CMS -> Pages or Admin Panel -> CMS -> Static Blocks. But while you developing your extension you might need to create a Magento CMS Page or Static Block programmatically.
Here is the way how you can achive it:
Creating a CMS Page:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
/* @var $installer Mage_Core_Model_Resource_Setup */ $installer = $this; $installer->startSetup(); Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); $cmsPage = array( 'title' => 'My CMS page', 'root_template' => 'one_column', // two_columns_left, two_columns_right, three_columns 'meta_keywords' => 'my page meta keywords', 'meta_description' => 'my page meta description', 'identifier' => 'my-cms-page', 'content' => 'My CMS page content goes here', 'content_heading' => 'My Content Heading', 'is_active' => 1, 'sort_order' => 0, 'stores' => array(0), ); Mage::getModel('cms/page')->setData($cmsPage)->save(); $installer->endSetup(); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
/* @var $installer Mage_Core_Model_Resource_Setup */ $installer = $this; $installer->startSetup(); Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); $staticBlock = array( 'title' => 'My CMS Block', 'identifier' => 'my_cms_block', 'content' => 'My CMS Block content goes here.', 'is_active' => 1, 'stores' => array(0), ); Mage::getModel('cms/block')->setData($staticBlock)->save(); $installer->endSetup(); |
Actually, magento has a fully-featured CMS system integrated in it. Browse through the pages to see the different elements you can add to your site.
thanks but where i have to add this code?
In your module sql updates.