1

我想将 lesti:FPC 与我开发的模块一起使用。

为了启用对 SEO 友好的 url,对模块的所有请求都被发送到模块索引操作,并且动态加载了一个模板。我怎样才能让 lesti:FPC 在这种情况下工作?

在模块布局文件(../layout/addon.xml)上,我有:

<block type="addon/index" name="addon_index" template="addon/index.phtml"/>

在模块 indexAction 我有:

if($condition)
{
  $this->getLayout()->getBlock('addon_index')->setTemplate('addon/a.phtml');
}
else
{
  $this->getLayout()->getBlock('addon_index')->setTemplate('addon/b.phtml');
}

将“addon_index”添加到 lesti:FPC 布局句柄是否足以缓存我的模块页面?

4

1 回答 1

1
Calling Dynamic Block in Lesti Fpc depends on conditions can be done using observer 

**Config.xml**

<frontend>
        <events>
            <core_block_abstract_to_html_before>
                <observers>
                    <atwix_test>
                        <type>model</type>
                        <class>namspace_test/observer</class>
                        <method>insertBlock</method>
                    </atwix_test>
                </observers>
            </core_block_abstract_to_html_before>
        </events>
    </frontend>

class Namespace_Test_Model_Observer
{
    public function insertBlock($observer)
    {
        /** @var $_block Mage_Core_Block_Abstract */
        /*Get block instance*/
        $_block = $observer->getBlock();
        /*get Block type*/
        $_type = $_block->getType();
       /*Check block type*/
        if ($_type == 'catalog/product_price') {
            /*Clone block instance*/
            $_child = clone $_block;
            /*set another type for block*/
            $_child->setType('test/block');
            /*set child for block*/
            $_block->setChild('child', $_child);
            /*set our template*/
            $_block->setTemplate('at.phtml');
        }
    }
}

最后,这是一个模板 at.phtml 代码:

echo $this->getChildHtml('child');

希望它会帮助你。

于 2014-08-01T16:05:51.607 回答