Hi,
I got an issue recently and I can’t resolve it on my own.
In my code $locale
returns current language - en
{{ $locale := .Site.Language.Lang }}
following that, I checked that outputs of following expressions
{{ (index .Site.Data $locale).nav.sidebar.navItems }}
and
{{ (index .Site.Data "en").nav.sidebar.navItems }}
return correctly the same data.
sidebar.json file looks like this
{
"navItems": [
{
"id": 1,
"title": "Parent",
"url": "/",
"parent": null
},
{
"id": 2,
"title": "Child",
"url": "/",
"parent": {
"id": 1
}
},
...
]
}
In code below
{{ $menus := (index .Site.Data $locale).nav.sidebar.navItems }}
{{ $mainMenus := where $menus "parent" nil }}
I get error error calling where: can’t iterate over
But when I change it for
{{ $menus := (index .Site.Data "en").nav.sidebar.navItems }}
Result is as expected.
I don’t want to have languages hardcoded due to other languages I will use in my app.