Magento 1.8 – How to Insert CMS Page Content Inside a Block

blockscmsmagento-1.8

How can I show the home page cms content inside a block? For instance, I have this content in my cms home page,

<p>welcome to my home page.</p>

And I want to insert this content inside a block called 'carousel',

this is my page.xml,

<default translate="label" module="page">
    <label>All Pages</label>
    <block type="page/html" name="root" output="toHtml" template="page/3columns.phtml">
        <block type="core/template" name="carousel" as="carousel" template="page/html/carousel.phtml">
            <label>Bootstrap Carousel</label>
            <block type="core/text_list" name="content" as="content" translate="label">
                <label>Main Content Area</label>
            </block>
        </block>
</default>

And this is my local.xml,

   <reference name="carousel">
        <block type="cms/block" name="cms_page_content">
            <action method="setBlockId">
                <block_id>cms_page_content</block_id>
            </action>
        </block>
    </reference>

Nothing is being printed out.

Any ideas?

EDIT:

Using a static block,

local.xml,

<reference name="carousel">
            <block type="cms/block" name="carouselx" before="carousel.content">
                <action method="setBlockId">
                    <block_id>carousel</block_id>
                </action>
            </block>
        </reference>

Best Answer

I guess you are mixing CMS blocks and pages. The home page content is as CMS page and what you are doing in your local.xml is adding a CMS block.

So you have two options. Either create a new CMS block inside of Magento admin or create your custom block type, pull the content of the CMS page there and then display it.

If you are not quite experienced with Magento I would suggest the first approach.

To create your custom block type you have to create a module (this answer will not cover it) and inside you have to create a block class with the following content:

<?php

class YourPackage_YourModule_Block_Page extends Mage_Core_Block_Template
{
    public function getContent()
    {
        $page = Mage::getModel('cms/page');
        $page->setStoreId(Mage::app()->getStore()->getId())
            ->load($this->getPageId(),'identifier');

        return $page->getId() ? Mage::helper('cms')->getPageTemplateProcessor()->filter($page->getContent()) : '';
    }
}

Then in your local.xml you can add your block to any exiting layout like this:

<reference name="...">
    <block type="your_module_alias/page" name="block_name" template="cms/cms-page-content.phtml">
        <action method="setPageId"><page_id>your_page_identifier</page_id></action>
    </block>
</reference>

And at last in your template at base/default/templates/cms/cms-page-content.phtml:

<?php $this->getContent() ?>