Search code examples
htmltemplatesgogo-gin

How To pass a function to template through c.HTML() in gin gonic framework (golang)


I want to pass a function through c.Html() function of type Context in gingonic.

For example, if we want to pass a variable, we use

    c.HTML(http.StatusOK, "index", gin.H{
        "user":   user,
        "userID": userID,
    })

And in html we call it as {{.user}}. But now, with function, how can we pass and call it in html template?


Solution

  • In order to create function in a template you need to create new FuncMap

    It`s look like the gin framework is creating the template pointer and cannot be overwritten.