vistad
November 11, 2023, 7:17pm
1
We all know how to range text or images - even data sets of those.
But how to range data sets that include both images and text lines? For instance if I want to range datasets like the following:
datasets:
- itemname:
category:
price:
image:
image:
image:
image:
Thanks!
Your YAML has duplicate keys.
vistad
November 11, 2023, 9:25pm
3
You mean a few images?
Yes, I need a few images. YAML, by specification, is not allowed to have duplicate keys in a mapping. So, how to overcome that restriction? If somebody knows.
Thanks!
Arif
November 11, 2023, 9:46pm
4
Maybe try this.
image:
- image 1
- image 2
- image 3
vistad
November 11, 2023, 9:51pm
5
That creates nested data. I could not range nested data. Could you?
If I name images as
image-1
image-2
etc. to avoid duplicate data?
Arif
November 11, 2023, 11:01pm
6
This (with a slight modification) might help
vistad
November 12, 2023, 12:30pm
7
Dear @jmooring and @Arif , thank you very much! I’ve found the solution.
Arif
November 12, 2023, 3:27pm
8
vistad:
I’ve found the solution.
Share it here and mark it as the solution for others who might see this in future.
1 Like
vistad
November 12, 2023, 4:52pm
9
Here is the solution I found:
The data structure:
imgs:
- itemname:
itemdescription:
price:
images:
- ""
- ""
- ""
- itemname:
itemdescription:
price:
images:
- ""
- ""
- ""
the HTML:
{{ if .Params.imgs }}
{{ range .Params.imgs }}
<div class="product-details">
<h3>{{ .itemname }}</h3>
<p>{{ .itemdescription }}</p>
<p>Price: {{ .price }}</p>
</div>
<ul class="image-gallery">
{{ range .images }}
<li>
<img src="{{ . | absURL }}" alt="">
</li>
{{ end }}
</ul>
{{ end }}
{{ end }}
1 Like
system
Closed
November 14, 2023, 4:52pm
10
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.