Hi @4nkown
Did you manage to figure this out yet?
One thing I noticed is that your if/else statement starts with elif, rather than if. If/else statements need to begin with {% if and end with an {% endif %} tag. Without those, the statement won’t work, and the syntax will be invalid. I’d recommend making these changes, and seeing if that solves the issue!
Let me know if you have any additional questions
-Byrne
well, actually it is just a piece of my code that’s why it starts with elif instead of if statement, ..and says i managed to make changes here.
Hi @4nkown,
I wanted to follow up to clarify if you are still looking for some guidance?
~Chloe
Hi @4nkown,
Your Django template syntax has multiple issues that could prevent it from rendering correctly. Here are the key problems and suggestions for fixing them:
Problems in Your Code:
-
Incorrect Use of {% elif %}
Without an Opening {% if %}
Block
{% elif %}
cannot be the first statement; it must follow {% if %}
.
-
Invalid {% catalog %}
Block Usage
{% catalog %}
and {% endcatalog %}
are not standard Django template tags. - If they are custom template tags, ensure they are correctly defined in your template library.
-
Incorrect has_category
Syntax
has_category catalog_item "watch" as in_category
should be wrapped inside an {% if %}
statement.
-
Logical Operators Misplacement
- The
or
operator should be explicitly used between conditions, not within a variable assignment. - The multiple
as in_category
assignments are likely incorrect.
Here's a simplified and corrected version:
{% catalog item.ProductID unpublished="cancel" %} {% if "Baume & Mercier" in item.ProductCategories %} {% with has_category catalog_item "watch" as watch %} {% with has_category catalog_item "Special Savings" as special %} {% with has_category catalog_item "Popular" as popular %} {% if watch or special or popular %} <!-- Content here --> {% endif %} {% endwith %} {% endwith %} {% endwith %} {% endif %} {% endcatalog %}
Fixes & Improvements:
Replaced {% elif %}
with {% if %}
for proper conditional logic.
Used {% with %}
to store has_category
results cleanly.
Ensured correct or
logic inside {% if %}
.
Next Steps:
- Verify that
{% catalog %}
is a valid custom tag. - Ensure
has_category
correctly returns True
or False
. - Use
{% debug %}
to check variable values in the template.
Hope this helps.
Best Regards.