As the question above is worded, @flyx’s is the most appropriate answer, however given external constraints (see my other question) I ended writing my own plugin to let data files textually include one another through liquid.
The goals of this plugin are to let the data be:
- DRY - (don’t repeat yourself) each model should be defined only once.
- Grouped - all similar data should be defined in the same format next to each other.
- Separated - different data should be defined in different places.
@flyx’s solutions here fail goals #2 and #3, requiring all different types of data to be defined in the same place and intermixing the definitions of foods and ingredients.
My proposed solution allows textual inclusion of one data file into another. This allows different models to be defined in different files, yet referenced from other files as if they were defined in the same place, in an arbitrary order. Applied to this problem, my solution would like this:
A.yml
{% include_relative_once _data/B.yml %}
a: &a
name: "Ay"
parents: []
children: [*b]
B.yml
{% include_relative_once _data/A.yml %}
b: &b
name: "Bee"
parents: [*a]
children: []
For the plugin itself, see this gist