I’ve been banging my head into the “intersect” function and can’t seem to figure out why it’s not working. According to the documentation (https://gohugo.io/templates/functions/#intersect), I should be able to pass two arrays as parameters to the function and have it return any elements that are in common. Here’s what I’m seeing:
The two arrays I have are both being pulled from .json files. Both are arrays of strings.
One is pulled from a page-specific data file:
{ “docTypes”: [“DT3”] }
The other is pulled from a global data file common/available to the whole site:
{ “techDocsGroup”: [“DT3”, “DT7”, “DT11”] }
Those are, of course, excerpts from larger .json files, but those are the only relevant json nodes.
In the code on my template page, where I’m trying to get this to work, I have the following lines:
{{ $dt := .docTypes }}
{{ $tdg := $.Site.Data.global.docTypeGroups.techDocsGroup }}
{{ $dt }} / {{ $tdg }} : {{ intersect .docTypes $.Site.Data.global.docTypeGroups.techDocsGroup }}
And the output I see on the page is as follows:
[DT3] / [DT3 DT7 DT11] : []
From the first part of the output line, I can see that the arrays are there and have data in them - but I can’t understand why the final “array” is showing as empty instead of showing “DT3” as it should. For what it’s worth, I also tried using the assigned/declared variables in the intersect function, instead of going back to the source, and had the same result.
Any suggestions/help/guidance would be greatly appreciated…