Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would I pull the content of a CMS page into a static block?

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

like image 478
Chris Avatar asked Mar 23 '11 23:03

Chris


People also ask

What is static blocks in website?

Static Blocks are sections of content within a page. Magento allows you to create these blocks of content which can then be implemented in various places on your website.

What are CMS blocks?

Content blocks are sometimes referred to as static blocks, or CMS blocks. They can be used to display fixed information such as text, images, and embedded video, and dynamic information that is provided by a widget or originates in a database or other source.


2 Answers

Haven't tested this, but it should work. If you have the unique ID of the cms page (not the identifier):

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

Otherwise if you have the page's identifier (i.e. URL key), use something like this:

$urlKey = "url_key";
$page->load($urlKey,'identifier');

Then finish with:

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

== EDIT ==

Added the template parsing steps as suggested by Alan

like image 70
Jonathan Day Avatar answered Sep 21 '22 02:09

Jonathan Day


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

like image 20
clockworkgeek Avatar answered Sep 21 '22 02:09

clockworkgeek