Home / golang

Golang Include Nested Template With Variable

Posted on:2020-02-29 Views:5972 Words:49

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>