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

**URL:** <https://discourse.gohugo.io/t/how-to-check-if-a-page-is-part-of-related-content/14735>\
**Category:** support\
**Created:** [October 16, 2018, 8:04pm UTC](https://discourse.gohugo.io/t/how-to-check-if-a-page-is-part-of-related-content/14735 "2018-10-16T20:04:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [October 16, 2018, 8:04pm UTC](https://discourse.gohugo.io/t/how-to-check-if-a-page-is-part-of-related-content/14735/1 "2018-10-16T20:04:25Z")

</div>

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:

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

```

```auto
{{ $related := .Site.RegularPages.Related . }}
{{ if lt $related 1 }}
{{ if eq $related 0 }}

```

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

---

<div class="post-metadata">

**Author:** ![regis](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/regis/32/4958_2.png) [@regis](https://discourse.gohugo.io/u/regis)\
**Post date:** [October 16, 2018, 8:22pm UTC](https://discourse.gohugo.io/t/how-to-check-if-a-page-is-part-of-related-content/14735/2 "2018-10-16T20:22:06Z")

</div>

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`.)

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

{{ if $related }}
[...]

```

---

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [October 16, 2018, 9:30pm UTC](https://discourse.gohugo.io/t/how-to-check-if-a-page-is-part-of-related-content/14735/3 "2018-10-16T21:30:31Z")

</div>

> [@regis](#):
>
> ```auto
> {{ $related := nil }} 
> {{ with .Site.RegularPages.Related . }}
> {{ $related = . }} 
> {{ end }}
> 
> ```

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.

---

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [October 16, 2018, 11:14pm UTC](https://discourse.gohugo.io/t/how-to-check-if-a-page-is-part-of-related-content/14735/4 "2018-10-16T23:14:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rdwatters](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/rdwatters/32/2848_2.png) [@rdwatters](https://discourse.gohugo.io/u/rdwatters)\
**Post date:** [October 17, 2018, 1:37am UTC](https://discourse.gohugo.io/t/how-to-check-if-a-page-is-part-of-related-content/14735/5 "2018-10-17T01:37:05Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [October 17, 2018, 7:41am UTC](https://discourse.gohugo.io/t/how-to-check-if-a-page-is-part-of-related-content/14735/6 "2018-10-17T07:41:15Z")

</div>

Thanks for the suggestion but it doesn’t work.

Tried the following variations:

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

```

```auto
 {{if gt (len $related) nil}}
<---Ok--->
{{ else if eq (len $related) nil }}
<--Nothing--->
{{ end }}

```

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

```

Oh well anyway…

---

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [October 17, 2018, 7:52am UTC](https://discourse.gohugo.io/t/how-to-check-if-a-page-is-part-of-related-content/14735/7 "2018-10-17T07:52:47Z")

</div>

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

> <https://github.com/gohugoio/hugo/issues/5328>
