1

I have created a widget text box that contains just an HTML tag.

<h1>Some heading</h1>

and then insert this widget to a CMS page with url: "cms_page_link". When I hit the CMS page URL, for example: http://example.com/cms_page_link/ the page show that widget content just as string with quoted:

"<h1>Some heading</h1>"

not the HTML element as I expected:

Some heading

Have anyway to get HTML tag as normal?

2
  • Can you post your code lines of widget here? Dec 25, 2017 at 10:26
  • Ah none code, I'm just create widget via admin
    – div
    Dec 25, 2017 at 10:54

2 Answers 2

1

Solution - "CMS Static Block" widget

  1. Go to Content -> Blocks, create a new block, write <h1>Some heading</h1> in it and save.

  2. Go to the CMS page you want to edit, insert the widget CMS Static Block, in the widget select the block you just created, then save the page and it will work.

html widget

Solution - Template

Write codes like this {{block class="Magento\Framework\View\Element\Template" name="blockname" template="Vendor_Module::test.phtml" my_vars="123,456"}} in your page. Create the template file in you module, you could use variable in it, it is a flexible way. You could get some info from How to retrieve variable from CMS page in Magento 2

2
  • Oh, I known this approach, but I am wanna to use a widget, not CMS blocks
    – div
    Dec 26, 2017 at 3:11
  • @viethung But it is indeed a widget type CMS Static Block, it doesn't have obvious difference with created a widget text box that contains just an HTML tag. If you doesn't like this way, you could use template, not widget. I will add it in the answer.
    – Key Shang
    Dec 26, 2017 at 3:29
0

You should use in the template htmlspecialchars_decode($variable);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.