I suspect that because I'm re-using the block dynamically that it will always have the same block id and therefore the fix will not work
That's right. And by adding dynamic content to a static block you are using it not as it is intended. You should use layout XML to add dynamic blocks with more flexibility.
If you insist on adding the content by selecting a static block in the category, you will need one static block for each category which then includes the dynamic template with different parameters. Which brings us to the next problem:
the CMS Static Block contains {{block type="core/template" template="template/category-block.phtml"}} which calls the custom phtml file.
This one is cached as well.
The inserted block is not a CMS block (cms/block
) but a regular template block (core/template
) so it does not even have a block id. But the problem stays: the cache key is the same for both instances.
This is how the cache key is generated for core/template
blocks:
public function getCacheKeyInfo()
{
return array(
'BLOCK_TPL',
Mage::app()->getStore()->getCode(),
$this->getTemplateFile(),
'template' => $this->getTemplate()
);
}
See Mage_Core_Block_Template
The actual cache key is a sha1 hash of all array values joined with "|". But you also can manually specify any unique string as cache key, for example:
{{block type="core/template"
template="template/category-block.phtml"
cache_key="CATEGORY_BLOCK_DEFAULT_STORE_CATEGORY_42"}}
Best Answer
The
enabled
flag on static blocks correspond directly to the db tableis_active
column, which is of typesmallint
.To enable this functionality in your own module, you'd have to extend that table and add a column onto the table
cms_block
(I use tinyint here, as a boolean):You'll also have to rewrite
Mage_Cms_Model_Resource_Block::_getLoadSelect
to consider your flag as well:Finally, add in the appropriate form dropdown by extending
Mage_Adminhtml_Block_Cms_Block_Edit_Form::_prepareForm
and adding the following: