Golang Include Nested Template With Variable

Updated at: 2020-02-29 Views: 804 Words: 49 Category: golang

golang gin controller

Send variable kv to template

c.HTML(http.StatusOK, "index.html", gin.H{
    "kv": kv,
})

template index.html

Include nested template footer.html, and send variable with dot (.) to footer.html

{{ template "footer.html" . }}

template footer.html

<span> open times:{{ .kv.Value }}</span>

Leave a Comment