Magento CE 1.9.2.0 – XML Tag to Add Array in Cache Tag for Layout File

block-cacheblocksce-1.9.2.0layoutxml

As magento1.9.2 is added cachetags function in to construct functon i must have to give seperate cachetags for each block element because its get conflict with varnish to read key. i have solved this issue in.phtml file to set key like below

 $this->getLayout()->createBlock('cms/block','',
         array(
         'cache_lifetime' => false,
         'cache_tags' => array(Mage_Cms_Model_Block::CACHE_TAG."_twocmspages")
                          ))->setBlockId("twocmspages")->toHtml(); 

but if need to assign same cache_tags using xml with setMethod how can i do this.

<block type="cms/block" name="block_id">
... set cachetag here
</block>

Is any one has idea how to add cache_tag array arrgument from XML ?

your help will be appreciated here.

Best Answer

Arguments in <action> can be defined as nested elements and will be converted to array:

<block type="cms/block" name="block_id">
    <action method="setTags">
        <tags>
            <tag1>cms_block_twocmspages</tag1>
            <tag2>( just in case you want to add more tags )</tag2>
        </tags>
    </action>
</block>

It should be noted that <tag1> and <tag2> will be the array keys, so you cannot use the same tag name and you cannot pass arrays with numeric indexes because XML tags cannot be numbers.

A more flexible solution is using JSON. Just specify which argument should be parsed as JSON with the json attribute of <action>:

<block type="cms/block" name="block_id">
    <action method="setTags" json="tags">
        <tags>["cms_block_twocmspages"]</tags>
    </action>
</block>