the image URLs are in the data file. should i put them in the _index.md file in the front matter?
i figured, if i put them in the data file, i could use them elsewhere in the site…
here is what i tried from your suggestion, in the branch bundle list.html layout file
{{ range .Resources.ByType "image" }}
{{ range .Site.Data.shows }}
{{ end }}
{{ end }}
but the problem is i want this to be a generic list.html, since i have many exhibitions, so how do i tell the layout file to extract THIS particular set of images?
You’re close. Since you do a range within a range, you have to grab the .Name before the context changes.
This will get you closer (if not all the way there). I’ll let you handle the rest from here – it’ll be beneficial for you to understand.
{{ $data := index .Site.Data .Params.dataFile }}
{{ range .Resources.ByType "image" }}
{{ $name := .Name }}
{{ range $data }}
{{ $img := .images.image }}
{{ if eq $name $img }}
<!-- Create your <img> element here -->
{{ end }}
{{ end }}
{{ end }}
<ul class="gallery">
{{ $data := index .Site.Data .Params.dataFile }}
{{ range .Resources.ByType "image" }}
{{ $name := .Name }}
{{ range $data }}
{{ $img := .media.images.image }}
{{ if eq $name $img }}
<li><img src="$img" /></li>
{{ end }}
{{ end }}
{{ end }}
</ul>
results in an error:
Error while rendering "section" in "": template: shows/list.html:5:13: executing "shows/list.html" at <index .Site.Data .Pa...>: error calling index: value is nil; should be of type string
This is not the correct way of defining a list (assuming you intended to define a list). Here, images is a map with five image keys. You probably want something like this instead:
{{ range $data }} will range over all of XYZ.yaml, returning
map[images:map[...]]
ABD
You need to range over $data.media.images. Then depending on which of the two list styles above you choose, access the image name by {{.}} or {{image}}
{{ range $data.media.images }}
<!-- if you use the first --> {{.}}
<!-- if you use the second --> {{.image}}<br>
{{ end }}
thanks @pointyfar for that detailed reply, without being cryptic. i’m still running up against problems,
my layout is under “layouts/shows/list.html”:
{{ partial "header" . }}
{{ .Content }}
<ul class="gallery">
{{ $data := index .Site.Data.shows .Params.dataFile }}
{{ range .Resources.ByType "image" }}
{{ $name := .Name }}
{{ range $data }}
{{ $img := .media.images }}
{{ if eq $name $img }}
<li><img src=$img /></li>
{{ end }}
{{ end }}
{{ end }}
</ul>
now this is still throwing up a
Error while rendering "section" in "": template: shows/list.html:5:13: executing "shows/list.html" at <index .Site.Data.sho...>: error calling index: value is nil; should be of type string
error, despite not having any other folder in “content/shows”
and my content is under “content/shows/XYZ/_index.md”:
---
dataFile: XYZ
---
also, my dataFile now looks like:
media:
images:
- 01.jpg
- 02.jpg
- 03.jpg
so i’m using the syntax you suggested, but clearly my loops are wrong
Where is your data file (XYZ.yml) located? We have been working here on the assumption that it is under yoursite/data/XYZ.yml. If so then $data needs to be:
{{ $data := index .Site.Data .Params.dataFile }}
Note: not .Site.Data.shows
which is the equivalent of
{{ $data := index .Site.Data "XYZ" }}
The error message actually gives you a hint:
error calling index: value is nil; should be of type string
When you call the index function, there is a nil value which should be a string. So to figure out which one that is, print out the two arguments you use:
{{ .Site.Data.shows }}{{ .Params.dataFile }}
Once you sort that out,
{{ range $data }}
...
will probably not work. Refer to my previous reply (the long one, towards the end)
@blablabla You ask many questions on this forum (which I encourage ), but each time you only provide minimal code snippets. Since others are volunteering their time to help you, the least you could do is take the time to create a small repo that reproduces your issue. It also fixes the “but it works on my computer” issues.
thank you both. the website i’m making is for an art collective i work with. i have spoken with them, and am trying to find a way in which i can open-source it now. however, they don’t want these questions showing up in search results related to the collective. a robots.txt file won’t be enough, as discourse.gohugo.io gets indexed, so what can i do?