Conditional statements and logical operators
Introduction
Understand if, elif, and else statements in Jinja
if, elif, and else statements in JinjaExample 1: Use 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: Use 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: Use logical operators in Jinja
Last updated
Was this helpful?
