go - Golang new template not working -
when run:
t, _ := template.parsefiles("index.html") t.execute(w, nil)
the page loads fine. when try , run
t := template.new("first") t, _ = t.parsefiles("index.html") t.execute(w, nil)
the thing loads blank page. trying change delimiter values in golang html template , make template, change delimiter values, parse file.
does else have problem?
the first version works expect because package-level parsefiles
function return new template has name , content of first parsed file.
in second case, though, you're creating template named "first"
, parsing 1 name "index.html"
. when call t.execute
on "first"
, it's still empty.
you can fix problem either:
- using
template.new("index.html")
, file name matches template name parse next; - providing template name want execute explicitly
t.executetemplate(w, "index.html", nil)
Comments
Post a Comment