0

I'm trying to get the fieldname of a pagerfanta results.

Twig template

{% for post in posts %}
{{ dump(post) }} 
{% endfor %}

The dump result is:

Users {#764 ▼
  -iduser: 11
  -username: "xzvdsfg"
  -password: "SHHHHHH"
  -lastlogin: DateTime {#691 ▶}
  -roles: []
}

i want to get the name of each entry without known it to place in a table like this

<table>
    <thead>
        <th>{{ fieldname }}</th>
    </thead>
    <tbody>
        <td>{{ fieldname.value }}</td>
    </tbody>
</table>

and get this result

<table>
    <thead>
        <th>username</th>
    </thead>
    <tbody>
        <td>xzvdsfg</td>
    </tbody>
</table>

I'm new at Twig templates Thanks!!!!

German
  • 1

1 Answers1

0

You could cast the object to array and iterate over then. You have to create your own twig filter to casting your object to array.

{% for key, value in post|cast_to_array %}

{% endfor %}
panche14
  • 651
  • 4
  • 8