Array question :(

Hi guys

in my data.songs.toml :

ranking = [ "/songs/luke-bryan/one-margarita.md", "/songs/dan-and-shay/10000-hours.md", "/songs/luke-combs/six-feet-apart.md" ]

on my homepage i have this:

	{{$type := .Site.Data.songs.ranking}}
{{ range (with .GetPage $type) }}{{ .Title }} {{ end }}

Why doesn’t this work? I spent hours on this dillemma …

Thank you guys

I think because your $type is a slice of values: .Site.Data.songs.ranking has these three values: "/songs/luke-bryan/one-margarita.md", "/songs/dan-and-shay/10000-hours.md", "/songs/luke-combs/six-feet-apart.md".

It might be that you first have to loop over those values with range, and then inside the loop use .GetPage.

Perhaps something like this (untested):

{{ $type := .Site.Data.songs.ranking }}

{{ range $type }}
    {{ $page := .Site.GetPage . }}
    {{ with $page }}
        {{ .Title }}
    {{ end }}
{{ end }}

I don’t know if this works since I cannot test your setup on my end, but this is what I’d try in your situation. :slight_smile:

1 Like

thank you for your quick response :slight_smile:

It looks great but I get an error message…

“can’t evaluate field Site in type interface”

No idea why…

I probably made a mistake. :slight_smile:

It looks like .Site.GetPage has to be $.Site.GetPage.

1 Like

Thank you so much!!! :slight_smile:

And what if i want to build a counter?

1 2 3 for each {{ .Title }}? :slight_smile:

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.