Hello,
I have got two keyword list (for the meta tag within the HTML header). So I have got:
.Site.Params.keywords
and optional on a page
.Params.keywords
both elements are lists, but .Params.keywords can be nil. So how can I concat these both list if one of them is nil in pseudo-code I will do
delimit .Site:params.keywords .Params.keywords ", "
Thanks
Give the intersect
template function a try. It takes two arrays and returns a new array with all elements that both have in common.
Based on the documentation I think this the solution, but on my example
{{ $a := slice "a" "b" "c" }}
{{ $b := slice "foo" "bar" "a" }}
{{ intersect $a $b }}
the intersect returns always an empty list
Above you stated that .Params.keywords
is optional on a page. In other words it could be nil. I’ve looked in the source code. As you can see does interesect
return an empty array if one of the given lists is nil.
From a mathematical point of view the function does not behave as expected. Let A be a non-empty set. When intersecting A with the empty set I expect the result to be A and not the empty set.
Yes, I think a not-empty set concat with nill, which is equal to the empty set, should be the non-empty set. I expected the mathematical point of view 
But for my example above with the two variable $a and $b which are not empty it returns on Hugo 0.18 also an empty set and I don’t understand why I get an empty set. In this case $a and $b are not-empty lists, so the result of intersect must be not-empty