有什么方法可以將變量(字符串、整數、布爾)傳遞給模板。例如(類似的東西):import ( "html/template")func main() { .... tmpl := template.Must(template.ParseFiles("templates/index.html")) mux.HandleFunc("/", func(rw http.ResponseWriter, req *http.Request) { varmap := map[string]interface{}{ "var1": "value", "var2": 100, } tmpl.ExecuteTemplate(rw, "index", varmap) }) // content of index.html {{define "index"}} {{var1}} is equal to {{var2}} {{end}}}
- 3 回答
- 0 關注
- 174 瀏覽
添加回答
舉報
0/150
提交
取消