Hey all, I’ve seen similar questions to this but I have a catch - my loop index needs modifying.
I have a query returning values for “bundle_child_01” through “bundle_child_10”, and instead of 10 if statements, thought I’d try a single for loop…
{% for i in (1..10) %}
{% capture var %} variant.bundle_child_{{ i | prepend: '00' | slice: -2, 2 }}.value {% endcapture %}
What am I doing wrong? No amount of checking [var] or var is returning anything but nulls or just the variable name, not it’s value.
Weirdly, this works in theory:
{% assign child_02 = "gid://tewtewt" %}
{% for i in (1..10) %}
{% capture var %}child_{{ i | prepend: '00' | slice: -2, 2 }}{% endcapture %}
{% if [var] %}
"{{ [var] }}"
{% endif %}
{%- endfor %}
In this case, [var] is gid://tewtewt. So what gives?
EDIT: Gave up. Did the below instead, much simpler ![]()
{% assign bundle_child_array = array %}
{% assign bundle_child_array[0] = variant.bundle_child_01.value %}
{% assign bundle_child_array[1] = variant.bundle_child_02.value %}
{% assign bundle_child_array[2] = variant.bundle_child_03.value %}
{% assign bundle_child_array[3] = variant.bundle_child_04.value %}
{% assign bundle_child_array[4] = variant.bundle_child_05.value %}
{% assign bundle_child_array[5] = variant.bundle_child_06.value %}
{% assign bundle_child_array[6] = variant.bundle_child_07.value %}
{% assign bundle_child_array[7] = variant.bundle_child_08.value %}
{% assign bundle_child_array[8] = variant.bundle_child_09.value %}
{% assign bundle_child_array[9] = variant.bundle_child_10.value %}
{% for bundle_child in bundle_child_array %}