I searched the web and could not find how to do this.
I want to add a static block that I have created in admin before to a cms-page. This works using either of this lines:
{{block type="cms/block" block_id="my_block_id"}}
{{block type="cms/block" block_id="my_block_id" template="cms/content.phtml"}}
Now I want to use a custom template, i.e.:
{{block type="cms/block" block_id="my_block_id" template="modulename/custom-template.phtml"}}
When I put it into the cms-page like this, the block is shown, but the "template"-tag is completely ignored – cms/content.phtml
is used.
WHAT I TRIED
I tried to extend class Mage_Block_Cms_Block and add setTemplate($this->getTemplate());
to _toHtml()
-function. The effect is the same as above – cms/content.phtml
is used.
I tried to extend class Mage_Core_Block_Template; of course I can set a template here, but I have problems getting the static block. I can't find how to get the block by block-id.
WHAT THIS QUESTION IS ABOUT / NOT ABOUT
I know how to do this with PHP.
I know how to do this with XML-files.
It s crucial to this question that the blocks can be managed in the backend.
I run Magento CE 1.7.0.0.
Thank you for your time!
Best Answer
You cannot change the template for a static block because the static block does not have a template. Take a look at the method:
Mage_Cms_Block_Block::_toHtml()
. The_toHtml()
method is used to render any block object, and in the case of the cms blocks it only renders the content of the block.If you want to wrap the content of any cms block in some markup you can try this:
And in the file
custom/block.phtml
do this:I hope this is what you needed.