Magento – passing variables to static blocks for dynamic use

static-block

recently i had an opportunity to pimp some cms pages of a customer. While we were exchanging ideas, we cam up with something that as far as i know is not going to work out of the box.

The Goal is to create one static block that can receive up to 5 variables ( in this case product ids ). With those ids, the static block should render the products related to those and create html-snippets. It shall work like a static block, where you easily enter a couple of ids and the static block should show them in a proper way.

i thought of something like:

{{widget type="cms/widget_block" template="cms/widget/static_block/default.phtml" block_id="16" variables="3,5,28,29"}}

where 3,5,28,29 is a comma seperated List of ids which the block could render via php…

Is there any way to achieve this? It would help so much to combine and relate content pages with products.

I am helpful for any idea!

Best Answer

I'm not sure whether this works the easy way.

You can try in your template to call

$blockId = $this->getData('variables');

this should contain your comma separated values.

If this doesn't work, you have to extend Mage_Cms_Block_Widget_Block and check there, where your values are and how to get them.

If you can't find them in Mage_Cms_Block_Widget_Block either, they are not passed. I have no clue where the widgets are parsed, so find this and change it, so you get your variable.

But I cross my fingers, that the first thing works.