I’m having a little trouble with my index.html
template and I was hoping someone could help me debug this. My goal is to have the first post on the first page show up in full using the idx_post
or idx_image
partials, with all other content displaying their summary. Below is the relevant part of my template annotated by my intent for clarity.
{{ partial "header.html" . }}
{{ $paginator := .Paginate (after 1 .Site.Pages) 5 }}
I want my paginator to contain all .Site.Pages
but the first, and go by 5s at a time.
{{ if .Paginator.HasPrev }}
{{ else }}
{{- range first 1 .Site.Pages }}
{{ if eq .Type "post" }}
{{ partial "idx_post.html" . }}
{{- end }}
{{ if eq .Type "image" }}
{{ partial "idx_image.html" . }}
{{- end }}
{{ end }}
{{- end }}
I couldn’t find the right way to say “not true” in the documentation so what I’m trying to do here is basically say "If there is a prior page, don’t do anything, but if there isn’t (e.g. you’re on page one), then render the first bit of content in .Site.Pages
using these partials based on type.
{{- range $paginator.Pages }}
{{ if eq .Type "post" }}
{{ .Render "summary" }}
{{- end }}
{{ if eq .Type "image" }}
{{ partial "idx_image.html" . }}
{{- end }}
{{- end }}
And lastly, over all the content in my paginator, render the summary template for all content types but image
where I want the full image post type to render.
The result of this seeing a summary on the first page and never seeing the idx_post.html
template being used.
I used to see the full content rendered with this template, but the first post was on every page:
{{ partial "header.html" . }}
{{- range first 1 .Site.Pages }}
{{ if eq .Type "post" }}
{{ partial "idx_post.html" . }}
{{- end }}
{{ if eq .Type "image" }}
{{ partial "idx_image.html" . }}
{{- end }}
{{- end }}
{{ $paginator := .Paginate (after 1 .Site.Pages) 5 }}
{{- range $paginator.Pages }}
{{ if eq .Type "post" }}
{{ .Render "summary" }}
{{- end }}
{{ if eq .Type "image" }}
{{ partial "idx_image.html" . }}
{{- end }}
{{- end }}