A bit over my head here, and the for the life me I could not find suitable solution to my usage case scenario.
I'm currently working on a project where in some scenario, when a user visit a certain page "Using Gin Framework Templates", part of the page content is rendered via data retrieved from the DB.
The issue with this approach is that Gin dose not seam to provide the ability to allow me to render any content Without fully escaping it.
I have developed previously with "PHP Framework", and used its template engine "Balde" I was able to if the need arises-ed to have the option to render HTML directly without escaping by using the following Directive "{!! $variableName !!}".
But in Using Gin, I was not successful into finding any builtin template directive that would allow me to render retrieved HTML content directly from DB.
Hope if anyone could support or provide solution or direction on how to solve this issue.
The following is a could sample and which results I get and which results I hope to get.
The following is a quick example of my current issue:
router := gin.Default()
router.LoadHTMLGlob("templates/*")
router.GET("/", func(c *gin.Context) {
db, err := gorm.Open(mysql.Open(configs.DB_Connection()), &gorm.Config{})
if err != nil {
panic("failed to connect database")
}
c.HTML(http.StatusOK, "index.html", gin.H{
"title": "<h1>Hello World</h1>",
})
})
Using the builtin template engine in Gin, I get the following results:
<h1>Hello World</h1>
What I'm hoping to get is:
Hello World
Please note that I'm getting that HTML directly from the DB.
Hello World
")`? Where `template.HTML` is the following: https://pkg.go.dev/html/template@go1.19.4#HTML – mkopriva Dec 26 '22 at 08:06