在细枝中使用数组变量

问题描述 投票:-1回答:1

我从控制器上以数组(可变广告)的形式从控制器中获取了一个变量,在树枝上,我使用了:

{% for ad in ads%}
<tr> <td> {{ad.xxx}}
 {% if app.user and app.user == ad.author%}
{{ad.yyyy}}
{% endif%}
</td> </tr>
{$ endfor%}

没有问题,很经典。我想使用例如

{% if app.user and app.user == ad.author%}

仅在for循环之前,为登录用户隐藏一个平台,但这不是他们的公告

twig symfony4
1个回答
0
投票

如果userAds是来自同一作者的广告的集合,则可以使用以下代码段:

{{ attribute(userAds|first, 'author') }}

{{ (userAds|first).author}}

{{ (userAds|first)['author'] }}

{% if app.user and (userAds|first).author == app.user %}
    <th>Action</th>
{% endif %}

© www.soinside.com 2019 - 2024. All rights reserved.