I am calling a html template in my html page and everything below the call is not being shown on the page.
This is the html page
{{define "TopPicks"}}
{{template "header" .}}
<div class="content">
{{range .TopPIcks.Results}}
{{end}}
</div> // Below this div
{{template "footer" .}}
{{end}}
After the closing content class div the footer is not being displayed. When I remove the
{{range .TopPIcks.Results}}
{{end}}
The footer appears at the bottom of the page and the html is injected at the bottom of the page but I cannot control where it is placed. What reason is this happening?
I am creating the TopPicks template in the main.go file.
t, err := template.New("TopPicks").Parse(`
{{define "body"}}
<ul>
{{$ImgUrl := "http://image.tmdb.org/t/p/w185" }}
{{range $movies := .Results}}
<li>{{$ImgUrl}}{{$movies.PosterPath}}</li>
<li>{{$movies.Adult}}</li>
<li>{{$movies.Overview}}</li>
<li>{{$movies.ReleaseDate}}</li>
<li>{{$movies.GenreIds}}</li>
<li>{{$movies.Id}}</li>
<li>{{$movies.OriginalTitle}}</li>
<li>{{$movies.OriginalLanguage}}</li>
<li>{{$movies.Title}}</li>
<li>{{$ImgUrl}}{{$movies.BackdropPath}}</li>
<li>{{$movies.Popularity}}</li>
<li>{{$movies.VoteCount}}</li>
<li>{{$movies.Video}}</li>
<li>{{$movies.VoteAverage}}</li>
{{end}}
</ul>
{{end}}
`)
err = t.ExecuteTemplate(w, "body", p) // This writes the client response
Can you see if something like this works for you. I had to use a different url to get json results, but I am hoping the overall outline will help you fix your problem. EDIT: Forgot to credit the code for calling the rest api - Joseph Misiti https://github.com/josephmisiti/go-citibike.