golang 引用嵌套 template 时传递模板变量

文章目录

    golang gin controller

    给模板传入变量 kv

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

    template index.html

    引用嵌套模板 footer.html,同时将变量通过点 (.) 传递给 footer.html

    {{ template "footer.html" . }}
    

    template footer.html

    <span>累计打开次数:{{ .kv.Value }}</span>