If we want our magento controllers to be able to load a static cms block (using AJAX for instance) and render the variable values that it can pass when we load the block then we can,
Load the block and declare an array of variables;
$block = $this->getLayout()->createBlock('cms/block')->setBlockId('block_id');
$variables = array();
Declare the variables we wish to pass (that we might have got from the params passed on to controller)... so we set the variable name and value as,
$variables['variable_name'] = $value;
Now when we return the html or render it we need to pass it through a filter, which has various directives method to run the codes in the parenthesis, {{ }}, within a static block,
Therefore we render it now as,
$filter = Mage::getModel('core/email_template_filter'); //or any of the
$filter->setVariables($variables);
echo $filter->filter($block->toHtml());
So now in the cms block anything with {{ var variable_name }} will be parsed. Therefore we can send variables and parameters to magento cms static block in this fashion even when we are rendering it using AJAX.
Hi there,
ReplyDeleteApologies for getting in touch out of the blue. I was impressed by your contributions on StackOverflow regarding Magento topics and wanted to ask if you might potentially be interested in a role at an e-commerce startup...
We recently launched a subscription-based business in the beauty and cosmetics space. It's going extremely well so far and we're now looking for a top-notch technical person to lead the technical side of the business as we take it to the next level. We're running on Magento.
Ideally, we're looking for someone based in London. Is that where you're currently based?
Would you be interested in having a chat about it? If so, what's the best number and time for reaching you?
All the best,
Matt
Matt Collins
Boudoir Privé
(matt at boudoirprive dot co dot uk)
was getting erro while passing variable but fixed now, thanks
ReplyDeletelooks like interesting widget!
ReplyDelete