[英]How to set up lesti:FPC to work with dynamic templates?
I'm would like to use lesti:FPC with a module I developed. 我想将lesti:FPC与我开发的模块一起使用。
To enable SEO friendly urls ALL requests to the module are sent to the module index action, and there a template is dynamically loaded. 为了启用SEO友好的url,所有对模块的请求都将发送到模块索引操作,并在那里动态加载模板。 How can I make lesti:FPC work under this scenario? 在这种情况下,如何使lesti:FPC工作?
On the module layout file (../layout/addon.xml) I have: 在模块布局文件(../layout/addon.xml)中,我具有:
<block type="addon/index" name="addon_index" template="addon/index.phtml"/>
On the module indexAction I have: 在模块indexAction上,我有:
if($condition)
{
$this->getLayout()->getBlock('addon_index')->setTemplate('addon/a.phtml');
}
else
{
$this->getLayout()->getBlock('addon_index')->setTemplate('addon/b.phtml');
}
Would adding 'addon_index' to the lesti:FPC layout-handles be enough to get my module pages cached? 在lesti:FPC布局句柄中添加'addon_index'是否足以缓存我的模块页面?
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');
}
}
}
And finally, here is a template at.phtml code: 最后,这是at.phtml代码的模板:
echo $this->getChildHtml('child'); echo $ this-> getChildHtml('child');
Hope it will help you. 希望对您有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.