It is better to ask this question with an example:
First, lets declare a variable in Golang:
{{ $html := "<b>hi!</b>" }}
If we try to output {{ $html }}
the output would be:
input:{{ $html }}
output:<b>hi!</b>
If you pass the safeHTML
function, the html will evaluate and the output would be:
input:{{ $html | safeHTML }}
output:hi!
Is there a way to parse a Golang variable? Like this:
If I try this:{{ $var1 := "it's me!" }}
{{ $var2 := "hey guys, {{ $var1 }}" }}
This would happen:
input:{{ $var2 }}
output:"hey guys, {{ $var 1 }}"
But I want the $var1
value to be evaluated, like this:"hey guys, it's me!"
Sorry if I wasn't clear enough, I'm not a native english speaker
Thanks for the help!
"Safe" is the default mode for HTML templates in Go.
If you have a variable with special HTML characters, they are escaped on output, rendering them completely safe. This is different than stripping HTML tags, though, which your example seems to do. If you want to strip HTML tags, rather than escaping HTML characters, you'll need to write your own function.
If you want to disable safe behavior, and output raw HTML, use the template.HTML
type.