我正在使用Gin Gonic和一个HTML模板文件。
我的模板文件中包含类似于的(多行)HTML注释。我希望保留HTML内容在返回的输出中。
c.HTML(http.StatusOK, "static/templates/mytemplate.html", gin.H{
"name": "World",
})
问题:如何配置模板引擎或c.HTML以不剥离模板中的HTML注释?
/static/templates/mytemplate.html:
Hello World
我的处理程序:
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",
})
}
编辑后,我尝试将注释添加为常量:
{{""}}
但是标签被转义为
<!-- foo -->
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号