How to render HTML strings to dom element in Meteor?

For example, I subscribe a post by ID, it has title and content values. “title” is plain text, so I can use {{title}} to display it directly. But “content” is strings like <p>asdf <i>sadaf &nbsp;asdf</i></p> .

I’ve tried using JQuery parseHTML in helper function but not work. I guess inside helper function, I cannot select the outside template’s $("#post-content").

I’ve also tried onRender, but don’t know how to find post->content inside the function.

So, what is the proper way to render HTML strings (this.content) into DOM elements?

Thanks a lot!

1 Like

if you do this {{{content}}} it will work.

2 Likes

Oh, yes, that’s amazing!

Be aware using {{{}}}. You are exposed to XSS attacks.

See here for more info: Safe to use URLs from users as HTML attribute values?

2 Likes

Thanks for the remind of XSS!

How can I achive this using Meteor + React??

See React’s Dangerously Set innerHTML post.