How to set up lesti:FPC to work with dynamic templates?

1.6k views Asked by At

I'm would like to use lesti:FPC with a module I developed.

To enable SEO friendly urls ALL requests to the module are sent to the module index action, and there a template is dynamically loaded. How can I make lesti:FPC work under this scenario?

On the module layout file (../layout/addon.xml) I have:

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

On the module indexAction I have:

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?

1

There are 1 answers

0
Manoj Chowrasiya On
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:

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

Hope it will help you.