Conditional statements and logical operators
Introduction
Understanding if, elif, and else Statements in Jinja
if, elif, and else Statements in JinjaExample 1: Using if and else Statements in Jinja
if and else Statements in Jinja{%- set dogs = 1 -%}
{%- set cats = 0 -%}
{%- if dogs -%}
{{- "we have dogs!\n" -}}
{%- else -%}
{{- "sorry no dogs today\n" -}}
{%- endif -%}
{%- if not cats -%}
{{- "sorry, no cats today.\n" -}}
{%- else -%}
{{- "we have cats!\n" -}}
{%- endif -%}
Example 2: Using if, elif, and else Ladders in Jinja
if, elif, and else Ladders in JinjaLogical Operators: and, or, and not in Jinja
and, or, and not in JinjaExample: Using Logical Operators in Jinja
Conclusion
Last updated
Was this helpful?
