Skip to main content
Answer

Display Fallback Content

  • July 11, 2025
  • 1 reply
  • 31 views

Forum|alt.badge.img+6

I want to display fallback content if the condition is not matched only one time. 

{% for feedItem in feeds.Firework.products %}
  {% if feedItem.productId == event.extra.line_items.0.product_id|floatadd:0 %}
    {{ feedItem.emailHtmlSmall | safe }}
  {% endif %}
{% endfor %}

 

Best answer by whereisjad

@JaydeepPatel Please find below a solution that functions effectively if displaying fallback content at the end, regardless of whether a match is found, is acceptable. Unfortunately, Django's templating logic does not support the use of a break statement.

{% for feedItem in feeds.Firework.products %}
  {% if feedItem.productId == event.extra.line_items.0.product_id|floatadd:0 %}
    {{ feedItem.emailHtmlSmall | safe }}
  {% endif %}


{% if forloop.last %}

//fallback option

{% endif %}
{% endfor %}

 

1 reply

whereisjad
Expert Problem Solver IV
Forum|alt.badge.img+16
  • Expert Problem Solver IV
  • Answer
  • July 11, 2025

@JaydeepPatel Please find below a solution that functions effectively if displaying fallback content at the end, regardless of whether a match is found, is acceptable. Unfortunately, Django's templating logic does not support the use of a break statement.

{% for feedItem in feeds.Firework.products %}
  {% if feedItem.productId == event.extra.line_items.0.product_id|floatadd:0 %}
    {{ feedItem.emailHtmlSmall | safe }}
  {% endif %}


{% if forloop.last %}

//fallback option

{% endif %}
{% endfor %}