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:

  1. using template.new("index.html"), file name matches template name parse next;
  2. providing template name want execute explicitly t.executetemplate(w, "index.html", nil)

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -