I have a cms block that is added to a page via layout xml.
<block type="cms/block" name="my_cms_block" as="my_cms_block">
<action method="setBlockId">
<block_id>my_cms_block</block_id>
</action>
</block>
It is then used on a page with the following snippet.
<?php echo $this->getChildHtml('my_cms_block'); ?>
Now what I would like to do is be able to pass variables into this block from the page that can be used in the cms block itself via {{var something}}
For example we have a cms block that we want to use across a selection of product pages but in this block we want to be able to use a product attribute say name or anything really.
Best Answer
I don't have a solution for passing variables to the block, but I have an other solution involving custom
{{...}}
directives.Here is a way to achieve what you need in your real scenario.
You need to put this in the block content
change
name
to what ever attribute code you need.Now you need to create the
attribute
directive. You can basically use anything as the directive name, but make sure it is one work without any uppercase letters. So{{attr}}
is ok{{productAttr}}
does not work.The cms blocks are parsed using the
Mage_Widget_Model_Template_Filter
, so you need to rewrite that class and add a new method: