Micro.blog

gr36
gr36

I have two overlapping categories on my blog (micro and photo) and for the life of me I can’t work out how to filter photo out of micro.

Every way I try using Hugo examples doesn’t work (crash) or gives me zero results.

😢

pratik
pratik

@gr36 IIRC, @sod solved this problem for @Mtt on the Help Forum

Mtt
Mtt

@gr36 Depending on your end goal, you could use a modified version of what’s in this conversation. Thanks to @sod for helping on that.

gr36
gr36

@Mtt @sod thanks for that it confirms I am on the right track, I think I am correct in using {{ $microposts := .Site.Taxonomies.categories.micro }} {{ $microposts := where $microposts ".Params.categories" "!=" "photo"}}

But nothing shows up

Mtt
Mtt

@gr36 That looks like you’re setting the variable to something then overwriting it. Are you trying to list all posts that have a Photo?

In reply to
gr36
gr36

@Mtt thats right, I find it easier to debug than all the interlocking where's.

I'm trying to list all posts in category micro that are not also in category photo

Mtt
Mtt

@gr36 Something like this may work. I typed it out on my phone and haven’t tested, so there may be a typo:

{{ if and (in .Params.categories "micro") (not (in Params.categories "photo")) }} <h3>{{ .Title }}</h3> {{ end }}

gr36
gr36

@Mtt thanks. That works for going through a loop great.

I just need to figure out how to do this to produce a range 🤔

sod
sod

@gr36 One solution using complement: {{ range .Site.Taxonomies.categories.micro.Pages | complement .Site.Taxonomies.categories.photo.Pages }}.

gr36
gr36

@sod that works perfectly! Never heard of complement before.

Thank you ❤️