Google+

Pages

Thursday, January 12, 2017

Custom CMS field showing widget calling code in frontend in Magento

Scenario:
I added custom field for CMS pages and wanted to show its value in sidebar.

Field type: Textarea
Wysiwyg: Enabled
Field Name: content_custom

I wanted to call a widget in content of this custom field.

For reference, I added below code to call widget:

{{widget type="cms/widget_page_link" anchor_text="My Custom Link" title="My Custom Link" template="cms/widget/link/link_block.phtml" page_id="153"}}

When I tried to show field's value in frontend, it displayed content as it was inputted from cms page:

{{widget type="cms/widget_page_link" anchor_text="My Custom Link" title="My Custom Link" template="cms/widget/link/link_block.phtml" page_id="153"}}

instead of rendering its html.

Solution: To render html instead of code calling widget, use below code:

echo Mage::helper('cms')->getBlockTemplateProcessor()->filter(Mage::getBlockSingleton('cms/page')->getPage()->getContentCustom());

Please try this code and let me know if you find any problem.

Thanks for visiting.

2 comments:

Alex Wood said...

Amazing tips! Thanks for the share!
magento company uk
magento company australia
magento company usa

kirznerdo brasilinfo said...

I would like to convey my appreciation for your kind-heartedness giving support to persons who should have assistance with this one matter. Your real commitment to getting the message across appears to be amazingly significant and has continually empowered women like me to arrive at their objectives. Your new useful facts entails so much a person like me and somewhat more to my colleagues. With thanks; from everyone of us.loja magento