Access specific data from CSV file in Jekyll
{{ site.data.planets.Mercury.diameter }}
Would work on a dictionary:
Mercury:
satellites: 0
diameter: 0.38
And this is probably the best way to query the data as you need it.
So, you would have the YAML:
Mercuy:
satellites: 0
diameter: 0.38
Venus:
satellites: 0
diameter: 0.95
Earth:
satellites: 1
diameter: 1.00
Mars:
satellites: 2
diameter: 0.53
And if you want to keep this in a CSV, what you could do is:
name, satellites, diameter
Mercury, 0, 0.38
Venus, 0, 0.95
Earth, 1, 1.00
Mars, 2, 0.53
And then, use a where
filter:
{{ (site.data.planets | where:"name","Mercury")["diameter"] }}
Now, for the sake of completeness, if you want to access Mercury
data on:
- name: Mercury
satellites: 0
diameter: 0.38
You would need to access it via:
{{ site.data.planets[0].diameter }}