Is there currently a way to exclude a given section from a list? Thanks to ‘where’, I can list only a given section, like this:
{{ range first 5 (where .Data.Pages "Section" "status") }}
{{ .Content }}
{{ end }}
But is there a way for me to e.g. then list all pages except those in section status?
The real context for this is that I have a “status” section of brief status messages which I display at the top of the home page, and then want to display the list of full posts & pages (everything that is not in section “status”) below that.
The work-around, obviously, is to give all status messages an ancient date, so they don’t appear in the list, but I’m wondering if there’s another way.
Thanks!
–
acodispo
It’s pretty easy to exclude things thusly:
{{ range .Data.Pages }}
{{ if neq .Section "status" }}
{{.Content}}
{{end}}
{{end}}
The only problem comes when you want to list only a certain number of them, since range first N will return N, but then you’ll possibly strip out some of those because they’re status messages. But if you don’t need to do that, it’s pretty simple.
Thanks, @natefinch! That will work nicely.
Actually, this is giving me an incomplete template error. Here’s what I’m using:
{{ range first 8 .Data.Pages }}
{{ if neq .Section "status" }}
<li><a href="{{ .RelPermalink }}">{{ .Title }}</a>, {{ .Date.Format "2006/01/02" }}</li>
{{end}}
{{ end }}
No rendering error if I remove the “if neq” clause and accompanying end tag.
Any ideas?
I think neq should be ne. Please try to change it
Thank you, @tatsushid, that works great!