Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento widget rendering in non-CMS content

Is there a simple way to hook into the Magento widget rendering feature on something other than CMS block or page?

I have a tooltips extension to display tooltips on custom options. There will be lots of products all with the same options and all needing the same tooltip text. While the tooltip extension we're using provides a means to declare snippets that can then be used on products, the snippets are added to individual products at setup time rather than referencing the single snippet instance. Thus if the tooltip content needs to change across all products we have to edit the snippet and then reapply the modified snippet to all products.

It would be preferable to be able refernce the snippet direct rather than just using it at product setup, but that's not how it works. So an alternative would be to include a static block in the tooltip description and reference the single description instance with our theme's already provided widget feature that works for on CMS pages e.g. {{widget type="cms/widget_block" template="cms/widget/static_block/default.phtml" block_id="xx"}}, where xx is the block created for this tooltip.

This needs the tooltip HTML description parsed through whatever it is in Magento that parses content HTML and processes any widget directives it contains.

I tried the following, where $tipstext is the tooltips HTML containing the widget directive, but no go. Didn't think it would be that simple!

Mage_Cms_Model_Template_Filter::filter($tipstext);

Anyhone have any idea if/how this could be achieved easily?

like image 737
Adam Lavery Avatar asked Dec 16 '22 07:12

Adam Lavery


1 Answers

The class Mage_Cms_Model_Template_Filter does not have a widgetDirective method so it does not know how to parse {{widget}} short codes. Try instead Mage_Widget_Model_Template_Filter:

Mage::getSingleton('widget/template_filter')->filter($text);
like image 174
Marius Avatar answered Dec 25 '22 03:12

Marius