Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 46 lines (29 sloc) 1.42 kB
4b298bf @kaos doc: a few more tags.
kaos authored
1
2 .. index:: tag; if
3 .. _tag-if:
4
5 if
6 ==
7
8 Show a block if the condition is true.
9
452e731 @mworrell core: accept optional 'with' keyword in include tag. Alias 'elseif' t…
mworrell authored
10 The ``{% if %}`` tag evaluates a variable and if the result is true (boolean true, number unequal to zero, non empty string or a non empty list) then the contents of the if-block are output. When the if-variable test fails then the optional ``{% elif %}`` blocks are evaluated. When the if and all optional elif variable tests fail, the optional ``{% else %}`` block content is output.
4b298bf @kaos doc: a few more tags.
kaos authored
11
12 Example::
13
779e492 @mmzeeman Added documentation for elseif
mmzeeman authored
14 {% if genre == "pop" %}
15 Popular music.
452e731 @mworrell core: accept optional 'with' keyword in include tag. Alias 'elseif' t…
mworrell authored
16 {% elif genre == "classical" %}
779e492 @mmzeeman Added documentation for elseif
mmzeeman authored
17 Classical music.
452e731 @mworrell core: accept optional 'with' keyword in include tag. Alias 'elseif' t…
mworrell authored
18 {% elif genre == "jazz" %}
779e492 @mmzeeman Added documentation for elseif
mmzeeman authored
19 Jazz
4b298bf @kaos doc: a few more tags.
kaos authored
20 {% else %}
779e492 @mmzeeman Added documentation for elseif
mmzeeman authored
21 The genre isn't pop, classical or jazz.
4b298bf @kaos doc: a few more tags.
kaos authored
22 {% endif %}
23
452e731 @mworrell core: accept optional 'with' keyword in include tag. Alias 'elseif' t…
mworrell authored
24 An ``{% if %}`` and ``{% elif %}`` tag can have an “and” or “or” expression as argument::
4b298bf @kaos doc: a few more tags.
kaos authored
25
26 {% if person_list and show_persons and full_moon %}
27 There are persons that we can show during full moon.
28 {% endif %}
29
30 Or for example::
31
47ccf9f @mworrell doc: correcting some quotes into curly quotes.
mworrell authored
32 {% if new_moon or daytime %} Guess you can’t see the moon. {% endif %}
4b298bf @kaos doc: a few more tags.
kaos authored
33
34 It is also possible to mix “and” and ”or” in one expression, so this is a valid::
35
36 {% if full_moon or daytime and cloudy %}
37
38 The ”not” operator can be used to negate a boolean value::
39
40 {% if full_moon or daytime or not clearsky %}
c58f443 @kaos doc: migrate the remaining tag docs.
kaos authored
41
452e731 @mworrell core: accept optional 'with' keyword in include tag. Alias 'elseif' t…
mworrell authored
42 .. note::
43 Besides the ``{% elif %}`` tag we also support the alias ``{% elseif %}``.
44
c58f443 @kaos doc: migrate the remaining tag docs.
kaos authored
45 .. seealso:: :ref:`tag-ifequal` and :ref:`tag-ifnotequal`.
Something went wrong with that request. Please try again.