CollectionType grouped by value in twig

Viewed 67

I am pretty new to symfony and i'm stuck on something.

I have a form where i want to edit Products for a UserCart. Each product has a ProductType.

I created a CollectionType of Products in my UserCartType to edit the products.

In my twig, i am currently iterating my CollectionType field to display the products

{% for product in form.products %}
    {{ form_row(product) }}
{% endfor %}

The result is good, but what i want is group my products in my twig by their ProductType.

It would look like this for example:

Cookies
    Cookie1
    Cookie2
Yogourt
   Yogourt1
   Yogourt2
   Yogourt

Where Cookies and Yogourt are ProductTypes you could find in the collection list of product

1 Answers
Related