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

前端 未结 3 780
眼角桃花
眼角桃花 2021-02-04 19:25

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.

相关标签:
3条回答
  • 2021-02-04 19:39

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

    0 讨论(0)
  • 2021-02-04 19:50

    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

    0 讨论(0)
  • 2021-02-04 19:52

    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 ({{...}})

    0 讨论(0)
提交回复
热议问题