I’m trying to follow the example given on the Jekyll docs (http://jekyllrb.com/docs/datafiles/#example-accessing-a-specific-author ) to access specific values from a row of a CSV file based upon a value specified in the Front Matter. I can’t even get the example code from the docs to work.
CSV file cities.csv:
name,description
Dallas,Big City in Texas
index.html content:
---
city: Dallas
---
{% assign city = site.data.cities[page.city] %}
<a rel="author"
href="https://twitter.com/{{ author.twitter }}"
title="{{ city.name }}">
{{ city.name }}
</a>
rdyar
October 3, 2017, 6:23pm
2
do you get an error?
is author defined? if not author.twitter
could be your problem.
Looks like site.data.cities[page.city]
doesn’t contain any data, which is why you’re not getting anything to output.
Jekyll has a handy filter called inspect
that you can throw onto the end of a variable to see what it contains.
{% assign city = site.data.cities[page.city] %}
{{ city | inspect }}
Which outputs nil
.
To do what you want I believe you need to loop through the site.data.cities
data file. Something like this works for me.
{% assign cities = site.data.cities %}
{% for city in cities %}
{% if city.name == page.city %}
<a rel="author"
href="https://twitter.com/{{ author.twitter }}"
title="{{ city.description }}">
{{ city.name }}
</a>
{% endif %}
{% endfor %}
3 Likes