Template and custom function; panic: function not defined

后端 未结 2 519
无人及你
无人及你 2021-02-04 01:39

Using html/template I am trying to use one of my own functions inside a template. Unfortunately I am unable to use the function map feature of go\'s templates. All

2条回答
  •  闹比i
    闹比i (楼主)
    2021-02-04 02:14

    The solution is to have same names in the function New() and Parse‌​Files() a suggested by @user321277

    var tmplGet = template.Must(template.New("base.html").Funcs(funcMap).Parse‌​Files("tmpl/base.htm‌​l", "tmpl/get.html"))
    

提交回复
热议问题