Passing FrontMatter variable index of array to yml file in a data folder

Here’s my version.

---
layout: archive
lang: en
ref: xl430-w250
tab_ref:
  ref1: xl430-w250
  ref2: xc430-w150
  ref3: xh430-w210
---

## Specifications

{% include en/dxl/specifications_x.md passed_ref=tab_ref.ref1 %}
{% include en/dxl/specifications_x.md passed_ref=tab_ref.ref2 %}
{% include en/dxl/specifications_x.md passed_ref=tab_ref.ref3 %}

If you have ref20 for example or the number if not fixed, then a for loop would make sense as I mentioned before.

{% for ref in page.tab_ref %}
{% assign name = ref[0] %} <!-- e.g. ref1 -->
{% assign value = ref[1] %}  <!-- e.g. xl430-w250 -->

### {{ name }}

{% include en/dxl/specifications_x.md passed_ref=value %}
{% endfor %}

Don’t indent in the for loop or the markdown ### I added will turn into a codeblock.


And the includes file:

{% assign item_data = site.data.dxl_x_info[include.passed_ref] %}

| Item              | Specifications           |
| :---------------- | :----------------------- |
| MCU               | {{ item_data.mcu }}      |
| Position Sensor   | {{ item_data.encoder }}  |
| Motor             | {{ item_data.motor }}    |
| Baud Rate         | {{ item_data.baudrate }} |
| Control Algorithm | {{ item_data.control }}  |

Note there’s no need to store the value pass in to the includes. I did an extra variable to make your table simpler.

1 Like