【发布时间】:2011-07-21 17:47:33
【问题描述】:
我想将 CMS 页面的内容提取到我的静态块中,如果您知道这样做的方法,我将不胜感激。
【问题讨论】:
标签: php templates magento content-management-system render
我想将 CMS 页面的内容提取到我的静态块中,如果您知道这样做的方法,我将不胜感激。
【问题讨论】:
标签: php templates magento content-management-system render
尚未对此进行测试,但它应该可以工作。如果您有 cms 页面的唯一 ID(不是标识符):
$page = Mage::getModel('cms/page');
$page->setStoreId(Mage::app()->getStore()->getId());
$page->load($pageId);
否则,如果您有页面的标识符(即 URL 键),请使用以下内容:
$urlKey = "url_key";
$page->load($urlKey,'identifier');
然后结束:
$helper = Mage::helper('cms');
$processor = $helper->getPageTemplateProcessor();
$html = $processor->filter($page->getContent());
return $html;
== 编辑 ==
添加了艾伦建议的模板解析步骤
【讨论】:
没有办法(据我所知)开箱即用。
但是,由于静态块编辑界面允许您将 widgets 插入到静态块中,我将实现一个呈现 CMS 页面内容的小部件。我有a basic implementation 我一直在玩,但是太忙了,无法充实。它是功能性的,但如果您尝试在任何一个 http 请求期间插入大量小部件,它就不会是超级性能。随意尝试一下;任何反馈表示赞赏。
如果您对如何以编程方式渲染 CMS 页面感兴趣,请查看 Mage_Cms_Block_Page::_toHtml() 方法。
$helper = Mage::helper('cms');
$processor = $helper->getPageTemplateProcessor();
$html = $processor->filter($this->getPage()->getContent());
$html = $this->getMessagesBlock()->getGroupedHtml() . $html;
return $html;
对$this->getPage() 的调用返回一个cms/page 模型。上面的额外代码是必要的,因为它将页面通过替换指令标签的过滤器({{...}})
【讨论】:
反过来做。在静态块和include it in a page 或其他静态块中创建您的内容。
【讨论】: