.Site.Data subdirectory and `first`

I’m hitting a massive wall with the following challenge. I have searched the forum and read some really complicated slice, map, index, and append docs and tutorials, but it goes way over my head. Thank you for your time & effort.

My data directory looks like this:


And I use the following code to:

  • range through one folder and files in /data
  • Show only movies from movie star X
    Example: On brad-pitt-movie-star.html I display the movies he played in. I used if in .data.stars $star, which ranges through all the stars from movies and if Brad was in it, it will match and display. The $star is set using Scratch and passed along to if in
{{ $model := .Scratch.Set "starpage" .Title }}
{{ $star := .Scratch.Get "starpage" }}
{{ range $parentKey, $parent := .Site.Data.movie }}
    {{ range $childKey, $child := sort . ".data.views" "desc" }}
      {{ if in .data.stars $star }}
        {{ .data.title }}
      {{ end }}
    {{ end }}
{{ end }}

range first 15

Where do I add first like in range first 15 .Site.Data.movie. I have tried a variety of positions. Do you have an idea?

You might want to boil this down a little bit if you want someone to respond.

1 Like