2

I want to make looping from array multidimention like database. that's example array that my made:

array[0]['name_product'] = 'big cola';
array[0]['size'] = '4';
array[1]['name_product'] = 'cfc';
array[1]['size'] = '1';
array[2]['name_product'] = 'hot dog';
array[2]['size'] = '1';
array[3]['name_product'] = 'pizza';
array[3]['size'] = '6';

I want to make looping with 2 condition, this is size == '1' and size > '1'. after it I want create loop from every condition, example:

size == '1', so:

no     name_product      size
1      big cola           4
2      pizza              6

size > '1':

no     name_product      size
1      cfc                1
2      hot dog            1

how about to make "no" is increment it with array and condition in twig ? I hope you can help me. thank you..

1 Answer 1

1

Your question is a bit unclear, I'm assuming you're looking for conditional loops. Twig has built-in support for that, here's the documentation. It was added in twig 1.2.

In your case you would make two loops (for the two tables) like this:

{% for product in products if product.size == 1 %}
    {# your first table #}
{% endfor %}

{% for product in products if product.size > 1 %}
    {# your second table #}
{% endfor %}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.