In templates\index.gohtml I am using this code:
{{template "header"}}
<h1>INDEX</h1>
{{template "nav"}}
<form action="/apply" method="post">
<label for="firstname">First Name</label>
<input type="text" name="firstname" id="firstname">
<input type="submit">
</form>
But I am getting the error:
html/template:index.gohtml:3:11: no such template "nav"
I guess, this is because nav
is defined in templates\includes
av.gohtml. If so, I don't know why I am not getting the same error for header
, since it's in the same directory.
my main.go looks like this:
func init() {
tpl = template.Must(template.ParseGlob("templates/*.gohtml"))
}
func main() {
http.HandleFunc("/", index)
}
func index(w http.ResponseWriter, r *http.Request) {
err := tpl.ExecuteTemplate(w, "index.gohtml", nil)
if err != nil {
log.Println(err)
http.Error(w, "Internal server error", http.StatusInternalServerError)
}
}
Any help would be appreciated.