excluded excluded - 6 months ago 56
Twig Question

Output array in Twig

I trying to output array from database to screen.
In my entity:

* @ORM\Column(type="array", nullable=true)
private $category;

In my twig template:

{% for category in user.profile.category %}
{{ category }}
{% endfor %}

Array to string convertion in ...

Where is my mistake ?


TWIG doesn't know how you want to display your table.

By the way, you should consider naming your variable $categories instead of $category, as you table contains several categories.

Then try this:

{% for category in user.profile.categories %}
   {{ category }}
{% endfor %}

If my answer doesn't help, please give us the structure of your array (is there any keys or sub-arrays in you table or is it just a list?)