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
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
My Handler:
Edit I tried to add the comments as constants:
But then the tags are escaped as
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
Code:
c.HTML(http.StatusOK, "static/templates/mytemplate.html", gin.H{
"name": "World",
})
Question: How to configure the template engine or c.HTML to not strip the HTML comments from the template?
More Detailed
Code:
/static/templates/mytemplate.html:
Code:
<!DOCTYPE html> <html lang="de"> <body> <!-- these lines are missing in the output --> Hello World </body> </html>
Code:
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",
})
}
Code:
{{"<!-- my comment goes here -->"}}
Code:
<!-- foo -->