Mindon.IDEA

Air off, Mind on ~ / Javascript+Golang, Sci, Health… /

How to Keep Comments in Golang Template?

When Using Golang templates, it removes all comments from the template output.

All IE condition comments lost and other features based on comments will be gone.

Here’s how to keep comments as they are from html/template output:

templates := template.Must(template.New("view").Funcs(template.FuncMap{
    "comment": func(t string) template.HTML {return template.HTML(t)}
}).ParseGlob("view/*.tpl"))

in the template

{{ comment “html-comment-source-code” }}

Aha, it works.

Comments