I’m parsing an YAML file with a list of publications, some of which have corresponding PDF files. I’d like to provide a link when a file exists, but not when it doesn’t.
This is what I’m currently doing:
{{ $publications := sort .Site.Data.publications.references "citation-key" }}
<ul>
{{ range $publications }}
<li>
{{ .title }}
{{ if fileExists "static/repository/{{ .id }}.pdf" }}<a href="/repository/{{ .id }}.pdf">[PDF]</a>{{ end }}
</li>
{{ end }}
<ul>
If I change the fileExists by providing one of the file names in the folder, it evaluates true and the corresponding links are correct
So
{{ if fileExists "static/repository/actualfilename.pdf" }}<a href="/repository/{{ .id }}.pdf">[PDF]</a>{{ end }}
Evaluates true and I get links for all of files.
What confuses me is that .id is then parsed correctly and I get working links to the right files. Why does .id not refer to the filenames correctly when checking if fileExists, but does when ranging over the file names for the links?