How to check if a Page is part of Related Content?

I am looking for a way to check whether a Page is part of Related Content or if a Page has Related Content?

Things I’ve tried that don’t work:

{{ $related := (.Site.RegularPages.RelatedIndices . "tags" ) }}
{{ if eq (in $related .Page) 0 }}
{{ if not (in $related .Pages) }}
{{ $related := .Site.RegularPages.Related . }}
{{ if lt $related 1 }}
{{ if eq $related 0 }}

Is this possible? Or am I doing something wrong here?

I always use with to check if related content is found before including the proper partial… and it works fine.

Until a better option, you could use with to set a bool variable… (this is untested, may have to fallback to .Scratch.)

{{ $related := nil }}
{{ with .Site.RegularPages.Related . }}
{{ $related = . }}
{{ end }}

{{ if $related }}

Thanks but the above throws an error on my end:
executing "_default/single.html" at <nil>: nil is not a command

Setting the boolean to 0 does not throw this error but it also doesn’t work.

I’ve been investigating and unfortunately this kind of filtering is not currently possible.

There is an unexported related.Document that is the basis of the Related Content interface.

But this is not reflected on the .Page.Type meaning that a .Page which is part of Related Content cannot be differentiated from a .Page that isn’t.

I suppose that my only option to achieve this kind of filtering would be to manually assign a front matter parameter to content files that will not be part of Related Content.

This is totally random spitballing here (on phone with no access to laptop, so preemptive apologies), but how about good-old-fashioned len with $related to check if related pages isn’t empty?

Thanks for the suggestion but it doesn’t work.

Tried the following variations:

 {{ $related := .Site.RegularPages.Related . }}
 {{if len $related}}
{{ else if not (len $related) }}
<---Not rendering--->
{{ end }}

 {{if gt (len $related) nil}}
{{ else if eq (len $related) nil }}
{{ end }}
 {{if gt (len $related) 1}}
{{ else if eq (len $related) 0 }}
<---Not Ok--->
{{ end }}

Oh well anyway…

For what it’s worth, I opened a GitHub issue here: