Problem: I want to create a table for each post whose contents changes for each post. The relevant data is in a YAML file located in /data/mydata.yaml. The table will be constructed using a shortcode.
Edit 3: Decided to trim leading “0” instead and stick with int.
Edit 2: Updated the code a little. Changed from int to string for purpose of comparison due to the way Hugo int deals with numbers that have a ‘0’ in front of them (treating them as octals).
Edit: Oh yeah… thanks!
So it appears to be working. You were right about the datafile.
Here is what is working for me (the $match math is due to $k1 being out of sync):
{{ $documentnumber := int (( .Get 0) | string.TrimLeft "0" ) }}
{{ range $k1, $v1 := .Site.Data.mydata }}
{{ $match := (add $k1 1) }}
{{ if eq $match $documentnumber }}
<table>
{{ range .category1 }}
<tr>
<td>{{.}}</td>
</tr>
{{ end }}
</table>
{{ end}}
{{ end }}