Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#20899 closed Bug (worksforme)

Elif templatetag does not work.

Reported by: tg56802@… Owned by: nobody
Component: Template system Version: 1.5
Severity: Normal Keywords: elif templatetag
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

'{{"Czas dostawy"|setChoose:"24h;48h;3 dni;Brak informacji"}}'

                        {% if "Czas dostawy"|setChoose:"24h;48h;3 dni;Brak informacji" == "24h" %}
                            <img src="dostawa_w24h.png"/>
                        {% elif "Czas dostawy"|setChoose:"24h;48h;3 dni;Brak informacji" == "48h" %}
                            <img src="dostawa_w48h.png"/>
                        {% elif "Czas dostawy"|setChoose:"24h;48h;3 dni;Brak informacji" == "3 dni" %}
                            <img src="dostawa_w3dni.png"/>
{% else %}
Inny
                        {% endif %}

If the first line return '48h', 'if statement' return 'Inny'.
If the first line return '28h', 'if statement' return correct value <img src="dostawa_w24h.png"/>.
So only first 'if statement' work. If I replace elif with 'if and endif statement' pairs all works correct.

Please tell me if it is bug or some hole in documentation.
Mabe '==' works only for if. With elif it is always False.
But with elif something is wrong.

Change History (2)

comment:1 by Russell Keith-Magee, 11 years ago

Resolution: worksforme
Status: newclosed

We have unit tests that validate that the elif tag works as documented. On the other hand, you've presented an example that apparently doesn't work, but depends on a "setChoose" template tag, for which you haven't provided any code.

I'd take a bet that the problem is with setChoose, not with elif -- or, at least, with the way that setChoose is interacting with the equality statement you're using.

If you want to assert that == doesn't work with elif, you'll need to narrow down your test case a bit so that it isn't relying on other factors.

Closing as "worksforme", because I can't reproduce with the information you've provided. If you can reduce your example to a minimal *and complete* test case, please reopen this ticket.

comment:2 by anonymous, 11 years ago

Thanks for quick answer, very good answer. And sorry for my ticket without any investigation.
I have checked in new example and elif == works nice.

After investigation in my previous code i see that it was my mistake:

SET_FILTER_RE = compile(r'''{({|\% if )\s*(["'](?P<name>[^"']+)["'])\s*\|\s*set(?P<type>Textarea|Text|Color|Check|Choose)(:["'](?P<default>[^"']+)["'])?''')

Regular expression insert new filters to user template, and it is very simply now - works only for {{ }} and {% if %}.

Thanks for answer.

Note: See TracTickets for help on using tickets.
Back to Top