skip to Main Content

I have 2 arrays “a_group” [a,a,a,a] and “b_group” [b,b,b]
I’m iterating with the following loop:

 {% for  a in a_group and b in b_group %}
         <p> {{ a }}: {{b}} </p>  
{% endfor %}

expected result:
a: b
a: b
a: b
a: No data available

what i actually get:
a: No data available
a: No data available
a: No data available
a: No data available

2

Answers


  1. If you need both an A element and a B element at the same time, you can always use indexes to cherry-pick them off, or nested loops. There is no concept of parallel processing that will help you otherwise.

    Login or Signup to reply.
  2. As per David sir’s guideline, this can possible using the indexes. below might help to implement in the code.

    {% assign a_group = 'a1,a2,a3'  | split: ',' %}
    
    {% assign b_group = 'b1,b2,b3' | split: ',' %}
    
    {% for a in a_group %}
    
        <p> {{ a }} : {{ b_group[forloop.index0] }} </p>
    
    {% endfor %}
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search