-1

I want to create a package for each element in the packages array. And if a package belongs to a type, to create a different row.

Let's say i have packages: A,B,C,D,A2,B3,C6,D8. A and A2 will be a row; B and B3 will be a different row and so on.

Tried to make a for loop for each package in packages and loop it if index0 % 2 ==0;

code looks like this

<div class="dashboard">
    <div class="row">
        <div class="container margin-bottom-60">
            <h2>boom</h2>
            <h4>lorem</h4>
            <br>
        {% for package in packages %}
            {% if loop.index0 % 2 == 0 %}
            <div class="col-md-4">
                <div class="packages-backend-elment">
                    <div class="col-md-12">
                        <h3>{{ package.title }}</h3>
                        <span>{{ package.shortTitle }}</span>
                        <div class="price">
                            {{ package.price }} 
                         </div>
                         <div class="description">
                             {{ package.shortDescription | raw }}
                         </div>
                         <div class="buttons">
                             <a href="#">
                                 <button type="button" class="btn-6 btn ink-reaction btn-flat dropdown-toggle paymentRequestBtn" data-urlaction="/employee/payment-requests/{{ package.id }}"></button>
                             </a>
                             <a href="#">
                                 <button type="button" class="btn-6 btn ink-reaction btn-flat dropdown-toggle show-packages-details"></button>
                             </a>
                         </div>
                     </div>
                 </div>
             </div>
             {% endif %}
        {% endfor %}
        </div>
    </div>
</div>
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Filu
  • 45
  • 6

1 Answers1

1

You will need to store the columns which already exist in a key-value array. It would start as an empty array, then you will loop through your items, check whether their value exists in the key-value array. If so, add the new value to the already created value, which should be an array. When you have finished this, you will have a key-value array, each key representing a column and each value representing the array of items in the column. You will have two nested loops. The outer loop will loop the columns. The inner loop will loop the values. And you will need to define your HTML to be displayed according to your needs.

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175