Parse html tags into html tempalte

Hello there

I’m converting the \n to <br> tag,

strings.Replace(data.Message, "\n", "<br>", -1)

when I want to show it in the HTML template the
tag is skipped and doesn’t work and just is shown in the template just like a text.
Screenshot from 2022-02-12 16-55-26

in the HTML template I’m rendering like:

<p style="text-align: justify;">{{.Message}}</p>

Are you using html/template or text/template?

The former will “autoescape” HTML characters to avoid injections.

You can use template.HTML() to mark a string as “safe”.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.