0

I created a widget that has a field for text as wysiwyg value. When I call up this value $block->getData('field_name') in frontend, I get something like:

<p>Content goes here</p> <ul> <li>Some text</li> <li>Some text 2</li> </ul> 

While the value should look like this:

Content goes here

  • Some text
  • Some text 2

How can I add HTML processing to my block? Thank you!

3
  • are you using $block->escapeHtml ? if so, then don't do it :) just echo the value and it should work, unless the tag values are encoded. Commented Mar 9, 2020 at 21:18
  • No, I call it so: <?= $block->getData('field_name') ?> Commented Mar 17, 2020 at 13:14
  • can you add your code for block? Commented Mar 17, 2020 at 18:52

2 Answers 2

0

Using magento way try this to print your html

<?= /* @noEscape */ $variable_name ?> 

And you can also print your html using echo

<?php echo $var; ?> 

Update

$str = '&lt;a href=&quot;https://www.w3schools.com&quot;&gt;w3schools.com&lt;/a&gt;'; echo html_entity_decode($str); 

Link here

2
  • I've tried both variants, but it does not work for me ;( I know, normally it should works without any special changes.. Commented Mar 17, 2020 at 13:14
  • try this html_entity_decode it may helps you Commented Mar 17, 2020 at 13:34
0

I've never seen someone get a static block using getData so I suspect that is the issue.

The typical way of loading CMS block content is like so:

<block class="Magento\Cms\Block\Block" name="myBlock"> <arguments> <argument name="block_id" xsi:type="string">myBlock</argument> </arguments> </block> 

Then you can call the block inside your template with $block->getChildHtml('myBlock')

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.