donglu4159 2015-09-04 00:27
浏览 153
已采纳

在Go中动态调用template.ParseFiles()而不是传入x个字符串的最佳方法是什么?

I want to load a folder of HTML templates in Go and right now I can only pass in each file path as a string in an argument.

Example:

templates = template.Must(template.ParseFiles("../web/html_templates/edit.html","../web/html_mplates/view.html"))

Works fine.

This and similar solutions won't work:

templates = template.Must(template.ParseFiles("../web/html_templates/*"))

I'd like to specify my templates in a config file but I currently can't. What's the best way to go about this?

  • 写回答

2条回答 默认 最新

  • dsgdfg30210 2015-09-04 00:39
    关注

    Use ParseGlob to parse a folder of HTML templates in one API call.

    templates = template.Must(template.ParseGlob("../web/html_templates/*.html"))
    

    See the Match function documentation for the glob syntax.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?