Hi all,
I’m trying to list events for a theater website. Tried several approaches now but without any ‘luck’.
I’d like to make a list so that it will be possible to assign a date to a theater. The theaters must be accessible from within the data folder, so that you don’t have to type all the info again and again.
Of course the dates will be variable and in the future.
{{ with .Params.agenda }}
{{ range $e := . }}
<span>{{ $e.datum }}</span>
<ul>
<li>
{{ range $.Site.Data.theaters.theater}}
<a href="{{ .Url }}">{{ .Naam }}</a> {{ .Plaats }}
{{ end }}
</li>
</ul>
{{ end }}
Now that works, But of course I don’t want the last value to be hard coded. I can’t just do obviously
{{ range $.Site.Data.theaters.$e.theater }}
However that’s the idea. I really have no clue how to rewrite it to make it readable for Hugo. I am trying now for a few days and am out of ideas (and out of search skills). Hope someone can toss me a line?
Thanks a lot! for this piece of clean and elegant code…
{{ range .Params.agenda }}
{{ .datum | time.Format ":date_long" }}
{{ $trimmed := trim .theater "data/theaters .json" }}
{{ with index site.Data.theaters $trimmed }}
- <a href="{{ .url }}">{{ .naam }}</a> - {{ .plaats }}
{{ end }}
{{ end }}
My final code. I followed the recommendation except for this line:
theater: data/theaters/groeneengel.json
I wanted to keep it like that because that will be the front matter output that Forestry.io will give me. I have to work with a CMS because when the site is finished someone else has to update it. So I trimmed that in a variable and put the variable in the with statement.