A
A
Alexey2015-12-07 17:45:01
symfony
Alexey, 2015-12-07 17:45:01

How to iterate through object using Twig?

Hello everyone! Recently started to get acquainted with fw Symfony2. And here's a question intersuet which has not yet found an answer. When displaying information from the database, I get an object with a number of properties (from a linked table). the object field is not a PersistentCollection and looks like this:
{{ dump (item1.conveniences) }}

Conveniences {#833 ▼
    -lift: 0
    -satellite: 0
    -internet: 1
    -wash: 1
    -airCond: 1
    -microwave: 1
    -shower: 0
    -sauna: 0
    -guard: 0
    -maxPeople: 5
    -balcony: 0
    -freeParking: 0

is there a way to iterate through this object like key, val in Twig template engine?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis, 2015-12-07
@eidicon

class Conveniences implements \Iterator
{
     // http://php.net/manual/ru/language.oop5.iterations.php
}

The object must be iterable.
Then iterate over it like you would a normal array.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question