【问题标题】:Twig and pagerfanta get the fieldname and the fieldname.valueTwig 和 pagerfanta 获取 fieldname 和 fieldname.value
【发布时间】:2016-12-01 09:24:25
【问题描述】:

我正在尝试获取 pagerfanta 结果的字段名。

树枝模板

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

转储结果是:

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

我想在不知道的情况下将每个条目的名称放在这样的表中

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

得到这个结果

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

我是 Twig 模板的新手 谢谢!!!!

【问题讨论】:

    标签: doctrine twig symfony pagerfanta


    【解决方案1】:

    您可以将对象转换为数组,然后进行迭代。您必须创建自己的 twig filter 才能将对象转换为数组。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-24
      • 2018-03-05
      • 2014-05-08
      • 1970-01-01
      • 2015-10-05
      • 2015-02-06
      相关资源
      最近更新 更多