Install CMS pages with your module

You can do this as shown in the following example of a Magento data setup script:

<?php

/* @var $installer Mage_Core_Model_Resource_Setup */
$oInstaller = $this;
$oInstaller->startSetup();
$aCmsPages = [
    [
        'title'            => 'FAQ',
        'root_template'    => 'two_columns_left',
        'meta_keywords'    => 'FAQ',
        'meta_description' => 'FAQ',
        'identifier'       => 'faq',
        'is_active'        => 1,
        'stores'           => 0,
        'sort_order'       => 0,
        'content_heading'  => 'Frequently Asked Questions',
        'content'          => <<<HTML
<h3>TEST</h3>
<p>Nullam condimentum elit ut iaculis luctus. Duis vel rutrum massa. Etiam vestibulum sem magna, ut euismod sapien tristique et. Integer sapien velit, elementum a elit at, tristique tincidunt tortor. In feugiat commodo mollis. Mauris venenatis lobortis purus, id blandit quam pulvinar pellentesque. Curabitur sed libero nulla. Sed auctor ex nisi, et feugiat massa convallis et.</p>
HTML
    ],
    [
        'title'            => 'Care tips and instruction manuals',
        'root_template'    => 'two_columns_left',
        'meta_keywords'    => 'Care tips and instruction manuals',
        'meta_description' => 'Care tips and instruction manuals',
        'identifier'       => 'care-tips-and-instruction-manuals',
        'is_active'        => 1,
        'stores'           => 0,
        'sort_order'       => 0,
        'content_heading'  => 'Care tips and instruction manuals',
        'content'          => <<<HTML
<h3>TEST2 </h3>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Aenean suscipit rhoncus nunc, nec mattis tellus venenatis at. Nunc bibendum, lorem sed suscipit tincidunt, mauris urna commodo mauris, et faucibus leo tellus non urna. Phasellus dictum facilisis nulla, ac accumsan est tristique in. Suspendisse viverra fringilla nunc. Fusce vel venenatis risus. Morbi non augue tempor, hendrerit massa ut, dictum quam. Nunc placerat sed orci ac viverra.
</p>
HTML
        ,
    ]
];

foreach ($aCmsPages as $aData) {
    /* @var Mage_Cms_Model_Block $oPage */
    $oPage = Mage::getModel('cms/page')->load(
        $aData['identifier'], 'identifier'
    );
    if ($oPage->getId()) {
        $aData['page_id'] = $oPage->getId();
        $oPage->setData($aData)
            ->save();
    } else {
        Mage::getModel('cms/page')->setData($aData)->save();
    }
}
$oInstaller->endSetup();

 

Leave a Reply

Your email address will not be published.

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.