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.

5 comments:

Alex Wood said...

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

ElijahBennet 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

Aanchal Kaura said...

You nicely explain the query ie Custom CMS field showing widget calling code in frontend in Magento. I'm dedicated Magento developer and love to read the technical blogs for Magento. Thanks for this post.

Eva Joseph said...

Thanks for sharing a good article....it is very nice and informative blog. PHP Services
Ecommerce Service Provider
Ecommerce website Development Company
Web Data Extraction Services
Data Extraction Services
Online Payment Gateway
CRM Services
Online Appointment Scheduling Software

Technokryon said...

Really useful stuff. Keep on posting related topics. Waiting for your next update

Magento development india
Custom magento development
magento ecommerce development company