I’m trying to parse this data file, called projects.yml
- name: My awesome project
type: Corporate website
work: Wordpress - Front and backend development.
text: Yoga is fun!
client: Lemon Co. Ltd
url: "http://www.google.com"
- name: My super duper project
type: Corporate website
work: Wordpress - Graphics, Front and backend development.
text: I love cake.
client: SomethingSomething
url: "http://www.facebook.com"
Inside a projects.html template, I run this loop:
{{ range .Site.Data.projects }}
{{ .name }}
{{ end }}
For some reason, I cannot get Hugo to output any data from this file. I must be doing something wrong, but I can’t figure out what. I’ve checked the yml file, it’s valid, so it must be my range?
1:
name: My awesome project
type: Corporate website
work: Wordpress - Front and backend development.
text: Yoga is fun!
client: Lemon Co. Ltd
url: "http://www.google.com"
2:
name: My super duper project
type: Corporate website
work: Wordpress - Graphics, Front and backend development.
text: I love cake.
client: SomethingSomething
url: "http://www.facebook.com"
_index.md contains only one variable inside the Front Matter called title (which is used as H1 in the template).
I’ve tried moving the projects.yml file in /data/projects but I still can’t parse the file. I’ve also tried your suggestion @Mikhail but still nothing on my end.
<!-- /layouts/section/projects.html -->
{{ range .Site.Data.projects }}
{{ .name }}
{{ end }}
Works with this projects.yml file:
# /data/projects.yml
1:
name: My awesome project
type: Corporate website
2:
name: My super duper project
type: Corporate website
Solution 2:
<!-- /layouts/section/projects.html -->
{{ range .Site.Data.projects.projects }}
{{ .name }}
{{ end }}
Works with this projects.yml file:
# /data/projects.yml
projects:
- name: My awesome project
type: Corporate website
- name: My super duper project
type: Corporate website
It’s a bummer that it wouldn’t work with my original file, as it’s a valid yml file and Hugo gave me no error, but I’m glad I’ve found a solution thanks to you guys.