0

I have used this blog https://webkul.com/blog/how-to-write-javascript-template-in-magento2/ to use x-magento-template. In this I can render data using such code:

<%- data.name %>

But it shows only text data, if I pass HTML, then also it renders it as text. Can someone tell me the solution of it?

1

<%= data.name %>

Magento 2 uses the Underscore.js template utility function to compile the x-magento-javascript templates. This is handled in mage/template. Notice the use of = versus -. I would recommend taking a look at their documentation, where you can find the following:

Template functions can both interpolate values, using <%= … %>, as well as execute arbitrary JavaScript code, with <% … %>. If you wish to interpolate a value, and have it be HTML-escaped, use <%- … %>.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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