The combination of @andy-jackson's answer, and the comment by @mb21 about data types put me on the right track. It turns out that my problem was caused by the fact that the value of page.comment_id
is an integer, whereas it needs to be a string to work in the file reference.
Surprisingly (at least to me), Liquid doesn't appear to have any built-in tags to convert an integer to a string! After some searching I did find this workaround that appends two quotation marks to an integer variable, which then magically returns a string. This works, but it's a bit hacky for my taste though.
Digging into the docs on Liquid variables I did find the "capture" tag, which captures the string inside two tags, and then assigns the result to another (string) variable. I applied this to page.comment_id
, and stored the result in a new variable comment_id
. I then used that variable in the way suggested by @andy-jackson.
Here's what I ended up with:
{% capture comment_id %}{{ page.comment_id }}{% endcapture %}
{% assign comments = site.data.comments-gh[comment_id] %}
{% for comment in comments %}
(processing code)
{% endfor %}
With these changes, the data file references work as expected on each page.