I’m attempting to display a href in a ternary statement in Twig, which works using a standard if else statement like the following:
{% if news_count|length > 0 %}
<a href="/{{profile.profile_id}}/news/">News {{news_count}}</a>
{% else %}
News 0
{% endif %}
When attempting to use a ternary statement as follows, I can’t get the link to format correctly.
{{ (news_count|length > 0) ? '<a href="/' ~ profile.profile_id ~ '/news/">News ' ~ news_count ~ '</a>' : "News 0" }}
This prints:
<a href="/10/news/">News 25</a> News 25
I’ve tried using the escape and raw filters at the end of the href value, but with no luck.
try:
BTW it seems that news_count is a int value already. so i assume “|length” isnt needed.