cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 2 - widget cms get html parameters

Magento 2 - widget cms get html parameters

I am using a wysiwyg field in my widget, value are well inserted but on frontend html markers and attributes are displayed as text.

 

{widget type="Vendor\Module\Block\Widget\Sliderimage"  textarea="<ul> <li>Base </li> </ul>"}}


I have to first decode html special chars to reencode it in order to display html, this is heartbreaking.

 

Now i am do this:

$allowedTags = ['a', 'b', 'p', 'li', 'ul'];
$textarea_1 = $block->escapeHtml(htmlspecialchars_decode($block->getData('textarea_1')), $allowedTags);

I use that widget block:

use Magento\Framework\View\Element\Template;
use Magento\Widget\Block\BlockInterface;

class Sliderimage extends Template implements BlockInterface

How can i hook beyond the getData functions to get my html parameter display in the right way ?

 

Thank you,
Damien.

 
4 REPLIES 4

Re: Magento 2 - widget cms get html parameters

Hello @KennedyA 

 

you can pass 

 

{{block test=test"}}

 

in block file yo will get value by

 

$this->getData('test')

if works then mark as solution

 


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: Magento 2 - widget cms get html parameters

The widget is inserted in a content cms page for exeample, the html fied use the wysiwyg to use html code:

{widget type="Vendor\Module\Block\Widget\Sliderimage"  textarea="<ul> <li>Base </li> </ul>"}}

We cannot use your solution.

Re: Magento 2 - widget cms get html parameters

Hello @KennedyA 

 

what do you mean?


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: Magento 2 - widget cms get html parameters

Your solution is not appropriate.