简体   繁体   中英

How can I display a nested struct field in a nested golang template?

I cant access concertLocation in the filters template. I have tried {{ .FormData.concertLocation}} but it doesnt display anything.

How can I parse the concertLocation value to my filters template?

Here is the code:

type forPage struct {
    Filters filter
}

type filter struct {
    Members         []int
    CreationDateMin int
    CreationDateMax int
    CreationDates   []int
    FirstAlbumMin   int
    FirstAlbumMax   int
    FirstAlbumDates []int
    Locations       []string
    FormData        struct {
        concertLocation string
    }
}

tmpl, err := template.ParseFiles("templates/index.html", "templates/filters.html", "templates/artists.html")
        if err != nil {
            panic(err)
        }

        newPage.Filters.FormData.concertLocation = r.FormValue("locations")
        tmpl.Execute(w, newPage)


 <div class="container">
      <div id="filters">{{ template "filters" .Filters }}</div>
    </div>

Found it. I had to capitalize it. This works {{ .FormData.ConcertLocation }}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM