Rendering HTML in variable using Jade

node.jsPug

node.js Problem Overview


I have some text stored in a variable which contains some HTML. For example, the <b>cat</b> in the hat. However, when I render it in Jade, it shows up with the tags instead of rendering the formatting. How can I fix this?

node.js Solutions


Solution 1 - node.js

> Code buffered by = is escaped by > default for security, however to output unescaped return values you > may use !=

p!= aVarContainingHTML

Pug Doc

Solution 2 - node.js

The syntax you need is :

!{yourJsVariable}

if you use #{yourJsVariable} it shows < >, but with !{} it doesn't.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiontofutimView Question on Stackoverflow
Solution 1 - node.jsagent-jView Answer on Stackoverflow
Solution 2 - node.jsakardonView Answer on Stackoverflow