我正在尝试在 Twig 的三元语句中显示 href,该语句使用标准 if else 语句,如下所示:
{% if news_count|length > 0 %}
<a href="/{{profile.profile_id}}/news/">News {{news_count}}</a>
{% else %}
News 0
{% endif %}
尝试如下使用三元语句时,我无法正确格式化链接。
{{ (news_count|length > 0) ? '<a href="/' ~ profile.profile_id ~ '/news/">News ' ~ news_count ~ '</a>' : "News 0" }}
这打印:
<a href="/10/news/">News 25</a> News 25
我尝试在 href 值的末尾使用转义和原始过滤器,但没有运气。