Error message: “django.template.exceptions.TemplateSyntaxError: Invalid block tag on line 82: ‘break’, expected ‘elif’, ‘else’ or ‘endif’. Did you forget to register or load this tag?”
This error is being caused because I am trying to use the break
statement in a block tag in a Django template.
To fix this error, I replace it with a return
statement from the block tag. Which will terminate the if
statement immediately. But the error remains the same.
My goal is to stop the for loops after listing 5 items from the category, Please I need help to fix this issue
Here is the code:
<div class="card">
<h5 class="mb-30">By Categories</h5>
<div class="categories-dropdown-wrap font-heading">
<ul>
{% for c in categories %}
<li>
<input
data-filter="category"
class="form-check-input filter-checkbox"
type="checkbox"
name="checkbox"
id="exampleCheckbox2"
value="{{ c.id }}"
/>
<a href="{% url 'core:category-product-list' c.cid %}">
<img src="{{c.image.url}}" alt="" />{{ c.title }}</a
>
</li>
{% if c.loop.index == 5 %}
<li>
<p>This is the 5th category.</p>
</li>
{% break %}
{% endif %}
{% endfor %}
</ul>
</div>
</div>