Range through one data file

Sorry to bother with this, the solution may be easy but I can’t find it.

I have this data/apps.yml

- name: app 1
  description: blablabla 1
  url: #1
  img: img1.png
- name: app 2
  description: blablabla 2
  url: #2
  img: img2.png
- name: app 3
  description: blablabla 3
  url: #3
  img: img3.png

and this

{{ range $.Site.Data.apps }}
  <div class="card">
    <img class="card-img-top" src="{{ .Site.BaseURL }}img/{{ .img }}" alt="Card image cap">
    <div class="card-body">
      <h4 class="card-title">{{ .name }}</h4>
      <p class="card-text">{{ .description }}</p>
      <a href="{{ .url }}" class="btn btn-primary">Visit</a>
    </div>
  </div>
{{ end }}

but the loop doesn’t output anything, and {{ printf "%#v" $.Site.Data.apps }} returns <nil>.
Any idea why?

Grrr I already read 3-4 posts on the forum about it but not the one you linked… sorry and thank you, I managed to make it work :slight_smile:

Had to add “apps:” as a first line of apps.yml and range with range .Site.Data.apps.apps.

Had to add “apps:” as a first line of apps.yml and range with range .Site.Data.apps.

It would be then range .Site.Data.apps.apps, right?

Yes I edited my answer, thank you!

If you do that with data.toml it should work as expected. With YAML you need a top identifier (e. g. section or app - doesn’t matter) to range through what’s underneath.