I have a Jekyll project where two separate pages (A.html and B.html) are displaying different content based on data in YAML files A.yml and B.yml respectively. Each yml file has a bunch of variables that are defined identically. I'd prefer to keep this common list of variables in a third file C.yml and include it into both A.yml and B.yml. How can I do this?
Things I've tried:
- Using * to reference global data like
*site.data.C.vars
- this didn't parse. - Put C.yml in _includes directory and use front matter treat the page like a liquid template and call
{% include C.yml %}
- this compiled, but the emitted html page had no content whatsoever.
Edit - example usage
Using a common data file in multiple views isn't quite sufficient for me because there would also need to be name-resolution logic in liquid to accompany it. Here's an example of what my data might look like:
A.yml
ingredients:
- avacado: &avacado
name: Avacado
color: Green
foods:
- *octopus_ceviche
B.yml
chefs:
- anthony_bourdain: &anthony_bourdain
name: Anthony Bourdain
hobby: Brazilian Jiu-Jitsu
foods:
- *octopus_ceviche
C.yml
foods:
- octopus_ceviche: &octopus_ceviche
name: Octopus Ceviche
taste: Delicious
If there's no way to include C.yml in A and B, then all the foods need to be shared in both places. If food is used in the md/html page entries need to be accessed by direct hash access (e.g. {{ site.data.foods[octopus_ceviche] }}
), which a) doesn't seem to work and b) feels like too much logic for a view.
*octupus_ceviche
is not Liquid name resolution, it's a YAML feature. Therefore, it can only reference entities in the same file. If you do not want to duplicate the values inC.yml
, you have to merge all data in one single file with root keysA
,B
andC
. – flyx