Embedded Data in Front Matter

This may seem like an easy question, but Iā€™ve been fighting it for a couple of days. I have a section labelled ā€œmusicā€ that basically is a set of blog posts containing mp3 files from performances by our local community band. In the past, it was a simple HTML file, but Iā€™d like to do it properly. I tried adding it to my front matter like:

[[params.music]]
url = "hugo.mp3"
name = ā€œThe Hugo Songā€
[[params.music]]
url = "html.mp3"
name = ā€œThe HTML Songā€

But I couldnā€™t parse that. I could put the TOML in a data file, but how can I specify that particular data file dynamically with the single.html template in the music layout folder? Iā€™d have about 100 separate data files + 100 posts. Thatā€™s why Iā€™d like to put it into the frontmatter if possible.

Iā€™m not sure if this is related to https://github.com/spf13/hugo/pull/2841

I tried again using YAML instead of TOML since TOML is brokenā€¦ My front matter excerpt looks like:

tags:         "Community Band"
music:        " Community Band"
playlist:
  - songs:
    - title: "Big Band Signatures"
      url: "bigbandsignatures.mp3"
   .- title: "Florentiner March"
     .url: "florentiner.mp3"
    - title: "New Colonial March"
      url: "newcolonial.mp3"

In my single.html template, my code should be something like this if I am correct:

      {{ range .Params.playlist.songs }}<li>{{.title}}</li>{{end}}

However, when I build, I get errored out on thatā€¦ What am I doing wrong?

Iā€™ve handled arrays like this in site before (to generate nested / multileveled menus for bootstrap), but this isnā€™t working for the page level array.

Whatā€™s the error message that you got? The issue that that pull request fixes is about a TOML array not parsed and turning up empty (without an error message). Perhaps the error message you got can help troubleshoot this issue.

ERROR: 2017/01/19 18:56:33 general.go:236: Error while rendering page music\2010-music-study-club-concert.md: template: theme/music/single.html:12:26: executing "theme/muā€¦

I originally had the data in toml just like the menu structure, but it just rendered blank lines or errored outā€¦ Thatā€™s when I swapped over to YAML because it was noted in the past that this was supposed to workā€¦

The line number of that error is the {{ rangeā€¦ line. Not much about the error. When I print the page params, all the data shows up, so it is read successfullyā€¦

Here is the printf of the .Params:

map[string]interface {}{ā€œplaylistā€:interface {}{map[interface {}]interface {}{ā€œsongsā€:interface {}{map[interface {}]interface {}{ā€œtitleā€:ā€œBig Band Signaturesā€, ā€œurlā€:ā€œbigbandsignatures.mp3ā€}, map[interface {}]interface {}{ā€œtitleā€:ā€œFlorentiner Marchā€, ā€œurlā€:ā€œflorentiner.mp3ā€}, map[interface {}]interface {}{ā€œtitleā€:ā€œNew Colonial Marchā€, ā€œurlā€:ā€œnewcolonial.mp3ā€}, map[interface {}]interface {}{ā€œurlā€:ā€œstarsandstripes.mp3ā€, ā€œtitleā€:ā€œStars and Stripes Foreverā€}, map[interface {}]interface {}{ā€œtitleā€:ā€œSymphonic Dances from Fiddler on the Roofā€, ā€œurlā€:ā€œsymphonicdances.mp3ā€}, map[interface {}]interface {}{ā€œtitleā€:ā€œThe Prayerā€, ā€œurlā€:ā€œtheprayer.mp3ā€}, map[interface {}]interface {}{ā€œtitleā€:ā€œThe Saintsā€, ā€œurlā€:ā€œthesaints.mp3ā€}, map[interface {}]interface {}{ā€œurlā€:ā€œtiptoe.mp3ā€, ā€œtitleā€:ā€œTiptoe through the Tubasā€}}}}, ā€œcategoriesā€:string{ā€œmusicā€}, ā€œtagsā€:string{ā€œComal Community Bandā€}, ā€œmusicā€:ā€œComal Community Bandā€}

You should remove the extra dots at the beginning of these lines.

.- title: ā€œFlorentiner Marchā€
.url: ā€œflorentiner.mp3ā€

Try a nested range:

{{range .Params.playlist}}
	{{range .Params.songs}}
		{{.title}}
	{{end}}
{{end}}

I actually didnā€™t have the dots in those linesā€¦ I had that when I was trying to fake indent on this site until I discovered that the four spaces indented codeā€¦

It works if I change it to:

{{range .Params.playlist}}
  {{range .songs}}
	{{.title}}
  {{end}}
{{end}}

Thank youā€¦ :slight_smile:

Glad it worked! :wink: