Giving a brief summary of the problem and the solution, so that others may benefit if they run into something similar.
@jnthnclrk has an aside element on each of his pages. In this aside there is a list of “Other Categories”. If the current page is a list of posts of category x, then the “Other Categories” list should not show any posts of category x. Additionally, only 4 posts should show in the “Other Categories” section.
Solution (if you know a better way to accomplish this, please do share):
{{ $.Scratch.Set "counter" 0 }}
{{ range .Site.Pages }}
{{ if not (in .Params.categories $.Title) }}
{{ $.Scratch.Set "counter" (add ($.Scratch.Get "counter") 1) }}
{{ if lt ($.Scratch.Get "counter") 5 }}
<! -- HTML -->
{{ end }}
{{ end }}
{{ end }}
Works great! I was completely wrong earlier about “if not (in” not working. It works great. I got in a pickle with scoping. Will post better examples in future.
@zwbetz I like your solution and am more than happy with Scratch loop logic, but I wonder if it’s possible to combine the “if not in” category logic with the range line? Because then we can presumably use Hugo’s first 4 function.