包含其他目录中的模板

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.

Right now you are only parsing files in the templates folder.
If you change this line

tpl = template.Must(template.ParseGlob("templates/*.gohtml"))

to this

tpl = template.Must(template.Must(template.ParseGlob("templates/*.gohtml")).ParseGlob("templates/includes/*.gohtml"))

it will parse the files in the templates folder, then parse the files in the templates/includes folder adding them to the existing parsed templates.