[SOLVED] Intersect yield empty array

I want to get a list of content from a certain section that has a certain front matter variable set.

My attempt:

{{ $section := where .Site.RegularPages "Section" .Section }}
{{ $refcontent := where .Site.RegularPages ".Params.contenttype" "reference" }}
{{ $refArticles := intersect $section $refcontent | shuffle }}

Problem is that the intersect array is empty. I know for a fact that this is incorrect, since I created content files in the current section that has that particular front matter variable.

If I use the len function to check the arrays’ length, all arrays except the intersect one contain content.

Using the where function with intersect gives the same problem.

{{ range where .Site.RegularPages ".Section" "intersect" $refcontent }}
    <!-- ... -->
{{ end }}

Any ideas where I go wrong?

Just learned from MooreReason here that the where function can be ‘nested inside’ itself. That way I don’t need to use intersect, and this also seems to be a less expensive operation.

My code is now:

{{ $section := where .Site.RegularPages "Section" .Section }}
{{ $sectionReference := where $section ".Params.contenttype" "reference" | shuffle }}
1 Like