Error: can't evaluate field categories in type interface {}

Continuing the discussion from How to grouping by categories:

I get the following error on Hugo 0.16:

ERROR: 2016/07/23 17:12:58 shortcode.go:565: error processing shortcode theme/shortcodes/chapter-content.html
ERR: template: theme/shortcodes/chapter-content.html:6:82: executing “theme/shortcodes/chapter-content.html” at <.Param
s.categories>: can’t evaluate field categories in type interface {}

The offending line in the shortcode file is:

{{ range (where $.Site.Data.Pages ".Params.categories" "intersect" .Params.categories).ByWeight }}

        <li><a href="{{ .Permalink }}" title="{{ .Title }}" >{{ .Title }}</a></li>

{{ end }} 

I know the code “intersect” works correctly since it does work when I add it to the single.html file in layouts, although there I use .Site.Pages. But in the shortcode the error message shows up.

What am I doing wrong?

Trye .Page.Params.categories

Thanks Bep. Unfortunately, now I get the ‘can’t iterate over nil’ error:

ERROR: 2016/07/27 12:07:51 shortcode.go:565: error processing shortcode theme/shortcodes/chapter-content.html
ERR: template: theme/shortcodes/chapter-content.html:6:18: executing “theme/shortcodes/chapter-content.html” at $.Site.Data.Pa…>: error calling where: can’t iterate over

The code that I used in the shortcode is this:

{{ range (where $.Site.Data.Pages ".Page.Params.categories" "intersect" .Page.Params.categories).ByWeight }}

    <li><a href="{{ .Permalink }}" title="{{ .Title }}" >{{ .Title }}</a></li>

{{ end }}    

The offending part of the error message (6:18) is the opening parentheses of the where filtering.

To compare, I have this in my layouts/_default/single.html:

{{ range (where .Site.Pages ".Params.categories" "intersect" .Params.categories).ByWeight }}

    <li><a href="{{ .Permalink }}" title="{{ .Title }}" >{{ .Title }}</a></li>
    
{{ end }} 

This latter code works totally fine. It goes past me what causes this difference.