Range .Site.Params with numbers?

Hello,

I’m trying to range my .Site.Params, but for some reason they won’t.

   # Articles will show up in home with this
    issue         = "March 2020"  

    [cover]
    current           = "9"

        [cover.7]
            issue                    =   "7"
            date                     =   "Issue 1, Vol 1 - March 2020"
            cover                    =   "issue2vol1"
            link                     =   "link 7"

        [cover.8]
            issue                    =   "8"
            date                     =   "Issue 2, Vol 1 - March 2020"
            cover                    =   "issue2vol1"
            link                     =   "link 8"

And this is what I am doing from a shortcode

{{ .Site.Params.cover.7.cover.issue }}
parse failed: template: shortcodes/issues.html:33: unexpected ".7" in operand

That’s my test to begin with the range, but for some reason is not working.

If I do:

{{ .Site.Params.cover}}

I get

 map[7:map[cover:issue2vol1 date:Issue 1, Vol 1 - March 2020 issue:7 link:link 7] 8:map[cover:issue2vol1 date:Issue 2, Vol 1 - March 2020 issue:8 link:link 8] 9:map[cover:issue1vol1 date:Issue 3, Vol 1 - March 2020 issue:9 link:link 9] current:9] 

But I can’t access each of those separately, nor I can’t access the values inside. ;-(

I can do

{{ index .Site.Params.cover "current" }}

And get the current number (9), but I can’t access the cover.7, cover.8, etc or any of the other values…

Hi

I think its how you nest things in your config

what happens if you do .Site.Params.cover.cover.7

example: .Site.Params.cover.current would return 9

and {{ .Site.Params.cover.7.cover.issue }} this wont work as there is not .issue set below …

    [cover.7]
        issue                    =   "7"
        date                     =   "Issue 1, Vol 1 - March 2020"
        cover                    =   "issue2vol1"
        link                     =   "link 7"

this … {{ .Site.Params.cover.7.cover}} will return "issue2vol1"

1 Like