フォルダー内のウォークを使用してファイルを動的に解析しようとしていますが、ファイル「path/file.html」のパスを設定できるようにしたいと考えています。ExecuteTemplate
しかし、私の問題は、フォルダー「path/folder/files.html」にファイルがある場合、ファイル名が同じ「files.html」になるため、実行できないことです。各テンプレートに I ParseFiles という名前を付けることはできますか?
一度にすべてを実行しようとしてもうまくいかない場合は、ファイルを 1 つずつ実行しても問題ありません。
// Parse file and send to responsewriter
func View(w http.ResponseWriter, path string) {
temp, err := template.ParseFiles("application/views/"+path+".html")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
} else {
temp.ExecuteTemplate(w, path, nil)
}
}