Can't paginate where pages' content isn't empty?

I’m trying to separately paginate:

  • Tags for which I created a content/tags/TAG/ with some content, and
  • The other tags

Easy, right?

{{ $paginator := .Paginate (where .Data.Pages ".Content" "ne" nil ) }}
<pre>.Content = {{ printf "%#v" .Content }}</pre>
{{ end }}

Well, wrong. That shows all the tags, but at least it reveals .Content is a string, and will never be nil. Progress! This’ll work, then, right?

{{ $paginator := .Paginate (where .Data.Pages ".Content" "==" "") }}
<pre>.Content = {{ printf "%#v" .Content }}</pre>
{{ end }}

Only the tags without content! Half success! Invert the operator…

{{ $paginator := .Paginate (where .Data.Pages ".Content" "!=" "") }}
<pre>.Content = {{ printf "%#v" .Content }}</pre>
{{ end }}

Nothing. Not a peep. Why not?

Because != should maybe be ne.

{{ $paginator := .Paginate (where .Data.Pages ".Content" ne "") }}

On another note: I would have started to work on this problem with frontmatter. If you have files for them then you have frontmatter and there you could set something like taxtype: content and then filter on this.

My reading of the documentation is that ne and != mean the same thing:

!= , <> , ne

true if a given field value doesn’t equal a matching value

A custom parameter in front matter strikes me as accident prone, so I spent some time checking out the default page variables. Luckily for me, checking WordCount against 0 does what I want for both == and !=:

{{ $paginator := .Paginate (where .Data.Pages ". WordCount" "!=" 0) }}
<pre>.Content = {{ printf "%#v" .Content }}</pre>
{{ end }}
1 Like