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

一世执手 提交于 2019-12-31 16:33:17

问题


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.


回答1:


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




回答2:


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




回答3:


There's no way (that I know of) to do this out of the box.

However, as the static block editing interface allows you to insert widgets into static blocks, I'd implement a widget that renders out the contents of a CMS page. I have a basic implementation I've been playing with, but have been too busy to flesh out. It's functional, but wouldn't be super performance if you tried to insert a large number of widgets during any one http request. Feel free to give it a try; any feedback is appreciated.

If you're interested in how to ro programmatically render out a CMS page, checkout 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;

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



来源:https://stackoverflow.com/questions/5412950/how-would-i-pull-the-content-of-a-cms-page-into-a-static-block

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!