在GO的模板系统中传递数据
接口{} {return vs}, })。parse(“ {{{template \“ image_row \” arg.5}}}”) 如果err!= nil { fmt.println(err) 返回 } err = t.execute(template.must(template.parsefiles)(“ index.html”,“ image_row.html”)),nil) 如果err!= nil { fmt.println(err) 返回 } } // index.html {{template“ image_row”。 | 5}}} // image_row.html {{定义“ image_row”}} 在此处{{index。 0}} {{index。 1}}} {{end}} 在Image_row Template中,可以使用内置索引函数访问参数。例如,{{index。 0}}将访问第一个参数(index 0)从index.html模板传递,在这种情况下为数字5。
此解决方案提供了一种通用的方式来传递和访问多个模板之间的数据,从而启用自定义功能和有效的代码重复使用。免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。
Copyright© 2022 湘ICP备2022001581号-3