- Author:
- showell
- Posted:
- June 17, 2009
- Language:
- Python
- Version:
- 1.0
- template smart_if
- Score:
- 0 (after 0 ratings)
The code posted here adds "elif" functionality to the smart if snippet 1350.
To use the snippet first follow the instructions for installing smart_if, then swap in the method shown on the left for the original smart_if method. You'll need to keep all the supporting classes from the original implementation, of course.
You can use it like this:
{% if 0 %} {% if 1 %} Hello Venus {% else %} unexpected {% endif %} {% elif 0 %} Hello Earth {% elif 0 %} Foo {% else %} Hello Mars {% endif %}
The code is compatible with original smart_if classes as of June 2009, and the use of "contains" in the Enders class relies on the current implementation of Parser.parse, which says "if token.contents in parse_until:" in the one place it uses the parse_until parameter, which seems like stable code to me.
The code works by recursively creating SmartIfNodes for the elif clauses.
Please login first before commenting.