How can I put the contents of a CMS page in a static block?

I want to pull the contents of a CMS page into my static block, if you know a way to do this, I would be grateful.

+6
php templates content-management-system magento render
source share
4 answers

Did not check it, but it should work. If you have a unique cms page id (not an id):

$page = Mage::getModel('cms/page'); $page->setStoreId(Mage::app()->getStore()->getId()); $page->load($pageId); 

Otherwise, if you have a page id (e.g. URL key), use something like this:

 $page->load($pageIdentifier,'identifier'); 

Then finish with:

 $helper = Mage::helper('cms'); $processor = $helper->getPageTemplateProcessor(); $html = $processor->filter($page->getContent()); return $html; 

== EDIT ==

Added parsing steps suggested by Alan

+18
source share

Do it the other way around. Create your content in a static block and include it in a page or other static blocks.

+3
source share

It is impossible (what I know) to do this out of the box.

However, since the static block editing interface allows you to insert widgets into static blocks, I would use a widget that displays the contents of the CMS page. I am the base implementation I played with, but was too busy to get rid of. This is functional, but will not be super-performance if you try to insert a large number of widgets during any one HTTP request. Feel free to try. Any feedback is appreciated.

If you are interested in how to programmatically render a CMS page, check out the Mage_Cms_Block_Page::_toHtml() method.

  $helper = Mage::helper('cms'); $processor = $helper->getPageTemplateProcessor(); $html = $processor->filter($this->getPage()->getContent()); $html = $this->getMessagesBlock()->getGroupedHtml() . $html; return $html; 

Calling $this->getPage() returns the cms/page model. The extra code above is necessary because it passes the page through filters that replace directive tags ( {{...}} )

+3
source share
  $model =Mage::getModel('cms/page')->load('welcome','identifier'); echo '<h2>'.$model->getContentHeading().'<h2>'; echo $model->getContent(); 

Magento CMS Page conten Displayed code Khaled saifullah

-3
source share

All Articles