Folks, need a bit of help, for one of my pages i have been using following code.
{{ range $name, $taxonomy := $.Site.Taxonomies.term_name.ByCount -}}
{{ end -}}
so far all has worked just fine, however now i want to filter this array and exclude a specific type of pages.
effective this right now gives me descending order list sorted by term_name however what i want is same list but exclude any entries with a specific type.
i can do that as a second level filter inside the range block however that doesn’t changes the order. any suggestions would be highly appreciated.
Maybe complement
is what you are looking for. If not, the most “hackiest” way would be an {{ if .Type "exclude"}}{{ else }} DO YOUR THING {{ end }}
inside of the range where “exclude” is the type you want to hide.
The complement function needs some “head wrapping around” but basically something along the line of complement $SELECTION_TO_FILTER_OUR $TAX_BY_COUNT
should work.
My problem is that the by count array gets the value of count which includes the other taxonomy and if we do exclusion afterwords the order of items get messy.
so lets say items number 5 and 10 have total counts as 20 and 4 but after excluding the other taxonomy we get 2 and 3 as count respectively. however since sorting was done initially so item 5 and 10 will remain in their own place.
I hope that explains the issue and concern.
I don’t understand this. The ByCount
method gives you descending order by count, not by term.
This template code:
{{ range site.Taxonomies.genres.ByCount }}
<h2><a href="{{ .Page.RelPermalink }}">{{ .Page.LinkTitle }}</a> ({{ .Count }})</h2>
<ul>
{{ range .Pages }}
<li><a href="{{ .RelPermalink }}">{{ .Title }}</a></li>
{{ end }}
</ul>
{{ end }}
Is rendered to something like this:
Where the content types are “books” and “films”.
Do you want to exclude one of these types, and have the count reflect only the included type?