fefit / fet

A golang template engine that can compile code into `html/template`, use syntax like the php template engine smarty.
MIT License
27 stars 4 forks source link

Unscape HTML variables #3

Open imayatech opened 1 year ago

imayatech commented 1 year ago

Is a way to pass HTML content in a variable and disable the escaping process?

P.e.:

<html><body>
{%$myvar = "<b>Hello</b> world"%}
{%$myvar}
</body></html>

Expected output:

<html><body>
<b>Hello</b> world
</body></html>
fefit commented 1 year ago

@imayatech since FET will translate the code into html/template template code, the func.go provides a method named safe to allowed HTML output. https://github.com/fefit/fet/blob/9e2ebbd55cc8678c84d2742234dc69c3bbc876b3/lib/funcs/funcs.go#L226 so you can use the method in the code like below:

<html><body>
{%$myvar = "<b>Hello</b> world"|safe%}
{%$myvar}
</body></html>

I hope that can solves your problem. thx for your issue~