Reputation: 2101
Right now in my Django template I'm writing a whole new a
tag if the conditional passes or fails. Is there a way to write this conditional in the a
tag so that there is only one a tag?
{% for app in apps %}
{% if app.app_id == "app-smart" %}
<a href='{{app.url}}' class='portfolio-link'>
{% else %}
<a href='{% url app.url %}' class='portfolio-link'>
{% endif %}
{% endfor %}
Upvotes: 0
Views: 1771
Reputation: 77902
Quite simply:
{% for app in apps %}
<a href='{% if app.app_id == "app-smart" %}{{app.url}}{% else %}{% url app.url %}{% endif %}' class='portfolio-link'>
{% endfor %}
There's nothing magic in django templates, that's just plain text templating.
Upvotes: 5