简体   繁体   English

Symfony 4 EasyAdmin-树枝模板中的渲染关联数据类型

[英]Symfony 4 EasyAdmin - Render association data type in twig template

Using EasyAdmin in my Symfony 4 app. 在我的Symfony 4应用程序中使用EasyAdmin。

Working on show view for the User entity. 在用户实体的显示视图上工作。

I want to display all my related (1-many) entities in the show view for User as lists I can style. 我想在显示视图中为我可以设置样式的用户列表显示所有相关的(1-很多)实体。

The default template for this datatype is @EasyAdmin/default/field_association.html.twig . 此数据类型的默认模板为@EasyAdmin/default/field_association.html.twig

How can I reference a list of entities for the user (Bookings, Assessment etc). 如何为用户引用实体列表(预订,评估等)。

I have tried adding {{ entity.assessments }} the user_show.html.twig but I get error: 我曾尝试在user_show.html.twig中添加{{ entity.assessments }} ,但出现错误:

Object of class Doctrine\ORM\PersistentCollection could not be converted to string

How can I render these related (associated) entities in this twig template? 如何在此树枝模板中渲染这些相关的(关联的)实体?

Try to iterate your array collection: 尝试迭代您的数组集合:

<ul>
    {% for item in entity.assessments %}
        <li>{{ item.name }}</li>
    {% endfor %}
</ul>

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

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