excluded excluded - 1 year ago 183
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 ?

Answer Source

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?)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download