A range that depends on the range


#1

Situation.
There is a range from the config file

{{ range .Site.Params.furniture }} {{ .alt_name }} {{ end }}

I want to add a range inside that will depend on {{.alt_name}}

And get something like this
{{ range .Site.Params.furniture }} {{ range .Site.Params.{{ .alt_name }} }} {{ .Title }} {{ end }} {{ end }}


#2
{{ range .Site.Params.furniture }}
{{ range .alt_name }}
{{ .Title }}
{{ end }}
{{ end }}

#3

It seems to me that this is not quite right.

I have the following configuration file:

[[params.footwear]]
name = "Coventry"
alt_name = coventry

[[params.footwear]]
name = "Canyon"
alt_name = сanyon

[[params.coventry]]
name = "128 (белый)"
logo = "coventry/coventry_1.jpg"
logo_mini = “coventry/coventry_1_thumb.jpg”

[[params.coventry]]
name = "146 (беж)"
logo = "coventry/coventry_2.jpg"
logo_mini = “coventry/coventry_2_thumb.jpg”

[[params.coventry]]
name = "155"
logo = "coventry/coventry_3.jpg"
logo_mini = “coventry/coventry_3_thumb.jpg”

[[params.coventry]]
name = "164"
logo = "coventry/coventry_4.jpg"
logo_mini = “coventry/coventry_4_thumb.jpg”

[[params.coventry]]
name = "183"
logo = "coventry/coventry_5.jpg"
logo_mini = “coventry/coventry_5_thumb.jpg”

[[params.coventry]]
name = "163"
logo = "coventry/coventry_6.jpg"
logo_mini = “coventry/coventry_6_thumb.jpg”

[[params.coventry]]
name = "142"
logo = "coventry/coventry_7.jpg"
logo_mini = “coventry/coventry_7_thumb.jpg”

[[params.coventry]]
name = "125 (Т0,7-0,9)"
logo = "coventry/coventry_8.jpg"
logo_mini = “coventry/coventry_8_thumb.jpg”

[[params.coventry]]
name = "125 (Т1,7)"
logo = "coventry/coventry_9.jpg"
logo_mini = “coventry/coventry_9_thumb.jpg”

[[params.coventry]]
name = "176"
logo = "coventry/coventry_10.jpg"
logo_mini = “coventry/coventry_10_thumb.jpg”

[[params.coventry]]
name = "1 Т2,0"
logo = "coventry/coventry_11.jpg"
logo_mini = “coventry/coventry_11_thumb.jpg”

[[params.canyon]]
name = "227"
logo = "canyon/canyon_1.jpg"
logo_mini = “canyon/canyon_1_thumb.jpg”

[[params.canyon]]
name = "125M"
logo = "canyon/canyon_2.jpg"
logo_mini = “canyon/canyon_2_thumb.jpg”

[[params.canyon]]
name = "229"
logo = "canyon/canyon_3.jpg"
logo_mini = “canyon/canyon_3_thumb.jpg”

[[params.canyon]]
name = "1"
logo = "canyon/canyon_4.jpg"
logo_mini = “canyon/canyon_4_thumb.jpg”

I want the range to be executed first

{{ range .Site.Params.footwear}}

And inside it, depending on {{.alt_name}}, another range

{{ range .Site.Params.{{ .alt_name }} }} {{ .name }} {{ end }}

{{ end }}


Those. Should be like this

{{ range .Site.Params.footwear}}
{{ range .Site.Params.coventry/canyon }} {{ .name }} {{ end }}

{{ end }}


#4

I do not understand TOML, but I think in YAML it should look like this:

params:
  footwear:
    coventry:
      name: Coventry
      alt_name: coventry
      logo: coventry/coventry_1.jpg
      logo_mini: coventry/coventry_1_thumb.jpg
{{ range .Site.Params.footwear}}
  {{ .name }}
  {{ .alt_name }}
  {{ .logo }}
{{ end }}

#5

Thank you for this solution. But I need a solution where two arrays were independent.


#6

If you still need help with this, I’d recommend describing why Mikhail’s original solution:

{{ range .Site.Params.furniture }}
{{ range .alt_name }}
{{ .Title }}
{{ end }}
{{ end }}

did not work for you.


#7

Look. I take an array from the config and I get a variable {{.alt_name}}.
Next, I need to take one of the config files and then output the values again.
The problem is that I need to somehow refer to the name of the array, the part of the name of which is the {{.alt_name}} variable.

So clearer or did I confuse you?


#8

I’m not a programmer, but I think the array should look like this.

arr1 = [ 1, 2, 3 ]
arr2 = [ "red", "yellow", "green" ]
arr3 = [ [ 1, 2 ], [3, 4, 5] ]
arr4 = [ "all", 'strings', """are the same""", '''type''']
arr5 = [ [ 1, 2 ], ["a", "b", "c"] ]