0
我想要一个func来扫描文件夹并找到所有的模板文件。然后调用template.ParseFiles来解析所有模板。我使用var tmplPathList []string
来记录所有的模板,并通过tmplPathList
到template.ParseFiles()
。如何将[]字符串转换为...字符串
func ParseFiles(filenames ...string) (*Template, error)
使用... string
作为参数。编译错误cannot use tmplPathList (type []string) as type string in argument to "html/template".ParseFiles
如何将[]string
转换为... string
?
var tmplPathList []string
for _, file := range tmplList {
tmplPathList = append(tmplPathList, dir + file.Name())
}
templates = template.Must(template.ParseFiles(tmplPathList))
我知道有一种方法,并且你向我展示了简单的方法。 – firelyu
@Flimzy这是我需要的。别再问问题了。 – firelyu