简体   繁体   中英

Twig and pagerfanta get the fieldname and the fieldname.value

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!!!!

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 %}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM