how to display the contents of the template?
package main
import (
"fmt"
"html/template"
"os"
)
func main() {
t := template.New("another")
t,e:=t.ParseFiles("test.html")
if(e!=nil){
fmt.Println(e);
}
t.Execute(os.Stdout, nil)
}
Why does not? test.html exists
You don't need to create a new template with New
and then use ParseFiles
on it. There is also a function ParseFiles
which takes care of creating a new template behind the scenes.
Here is an example:
package main
import (
"fmt"
"html/template"
"os"
)
func main() {
t, err := template.ParseFiles("test.html")
if err != nil {
fmt.Println(err);
}
t.Execute(os.Stdout, nil)
}