简体   繁体   English

Twig和pagerfanta获取字段名和fieldname.value

[英]Twig and pagerfanta get the fieldname and the fieldname.value

I'm trying to get the fieldname of a pagerfanta results. 我正在尝试获取pagerfanta结果的字段名称。

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!!!! 我是Twig模板的新手,谢谢!!!

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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