Nathn
Nathn

Reputation: 429

Execute HTML code contained in a variable

I have a string variable that contain HTML code and I want it to render instead of displaying it as text. I tried different Pug configurations :
If the variable content contains the string <a href="/something">@something</a> :

p(style="white-space: pre-line")
    | #{content}

displays the string as text and doesn't render it,

p(style="white-space: pre-line")
    #{content}

display this : <@something>@something> with the first @something being clickable,

p(style="white-space: pre-line")
    #[content]

and this returns an error.

Is there a possible way to do this ? Thanks !

Upvotes: 0

Views: 231

Answers (1)

Anis R.
Anis R.

Reputation: 6912

Simply replace the hash of #{content} with an exclamation mark: !{content}. This is called unescaped string interpolation and should render your content without escaping HTML tags:

p(style="white-space: pre-line")
    | !{content}

Upvotes: 1

Related Questions