I'm using Gin Gonic with a HTML template file.
My template file contains (multi line) HTML comments of the kind <!-- my comment goes here-->
.
I want that the HTML content is preserved in the output which is returned by
c.HTML(http.StatusOK, "static/templates/mytemplate.html", gin.H{
"name": "World",
})
where c
is a *gin.Context
.
Question: How to configure the template engine or c.HTML to not strip the HTML comments from the template?
More Detailed
/static/templates/mytemplate.html
:
<!DOCTYPE html>
<html lang="de">
<body>
<!--
these lines are missing in the output
-->
Hello World
</body>
</html>
My Handler:
func NewRouter() *gin.Engine {
router := gin.Default()
// ... load templates from file system ...
router.GET("/foo", fooHandler)
return router
}
func fooHandler(c *gin.Context) {
c.HTML(http.StatusOK, "static/templates/mytemplate.html", gin.H{
"name": "World",
})
}
Edit I tried to add the comments as constants:
{{"<!-- my comment goes here -->"}}
But then the tags are escaped as
<!-- foo -->