{"result":{"depiction_url":null,"edges":{"refers":{"objects":[{"created":"2026-09-09T13:48:28Z","object_id":{"id":1366,"is_a":["text","documentation","reference","template_tag"],"name":"doc_template_tag_tag_ifequal","title":"ifequal","uri":"https:\/\/zotonic.com\/id\/1366"},"seq":1000000},{"created":"2026-09-09T13:48:28Z","object_id":{"id":1367,"is_a":["text","documentation","reference","template_tag"],"name":"doc_template_tag_tag_ifnotequal","title":"ifnotequal","uri":"https:\/\/zotonic.com\/id\/1367"},"seq":1000000}],"predicate":{"id":2409,"is_a":["meta","predicate"],"name":"refers","title":{"_type":"trans","tr":{"en":"Refers"}},"uri":"https:\/\/zotonic.com\/id\/refers"}},"relation":{"objects":[{"created":"2020-05-30T05:48:05Z","object_id":{"id":1366,"is_a":["text","documentation","reference","template_tag"],"name":"doc_template_tag_tag_ifequal","title":"ifequal","uri":"https:\/\/zotonic.com\/id\/1366"},"seq":1000000},{"created":"2020-05-30T05:48:05Z","object_id":{"id":1367,"is_a":["text","documentation","reference","template_tag"],"name":"doc_template_tag_tag_ifnotequal","title":"ifnotequal","uri":"https:\/\/zotonic.com\/id\/1367"},"seq":1000000}],"predicate":{"id":303,"is_a":["meta","predicate"],"name":"relation","title":{"_type":"trans","tr":{"nl":"Relatie","en":"Relation"}},"uri":"http:\/\/purl.org\/dc\/terms\/relation"}},"subject":{"objects":[{"created":"2026-09-09T13:48:28Z","object_id":{"id":2555,"is_a":["categorization","keyword","keyword_information_type"],"name":"zotonic_topic_reference","title":"Reference","uri":"https:\/\/zotonic.com\/id\/2555"},"seq":1},{"created":"2026-09-09T13:48:29Z","object_id":{"id":2563,"is_a":["categorization","keyword","keyword_audience"],"name":"zotonic_topic_frontend_developer","title":"Frontend developer","uri":"https:\/\/zotonic.com\/id\/2563"},"seq":2},{"created":"2026-09-09T13:48:29Z","object_id":{"id":2620,"is_a":["categorization","keyword","keyword_architecture"],"name":"zotonic_topic_template","title":"Template","uri":"https:\/\/zotonic.com\/id\/2620"},"seq":3},{"created":"2026-09-09T13:48:29Z","object_id":{"id":2641,"is_a":["categorization","keyword","keyword_task"],"name":"zotonic_topic_render","title":"Render","uri":"https:\/\/zotonic.com\/id\/2641"},"seq":4},{"created":"2026-09-09T13:48:29Z","object_id":{"id":2661,"is_a":["categorization","keyword","keyword_data_type"],"name":"zotonic_topic_boolean","title":"Boolean","uri":"https:\/\/zotonic.com\/id\/2661"},"seq":5}],"predicate":{"id":308,"is_a":["meta","predicate"],"name":"subject","title":{"_type":"trans","tr":{"en":"Keyword"}},"uri":"http:\/\/purl.org\/dc\/elements\/1.1\/subject"}}},"id":1364,"is_a":["text","documentation","reference","template_tag"],"links":[{"rel":"self","target":"https:\/\/zotonic.com\/.zotonic\/websub\/topic\/1364"},{"rel":"hub","target":"https:\/\/zotonic.com\/.zotonic\/websub"}],"medium":null,"medium_url":null,"name":"doc_template_tag_tag_if","page_url":{"en":"https:\/\/zotonic.com\/docs\/1364\/if","x-default":"https:\/\/zotonic.com\/docs\/1364\/if"},"preview_url":null,"resource":{"version":3997,"pivot_location_lat":null,"title":"if","is_authoritative":true,"body":"<aside><p>See also<\/p><p><a href=\"\/id\/doc_template_tag_tag_ifequal\" class=\"doc-reference doc-reference-tag\"><code>tag#ifequal<\/code><\/a> and <a href=\"\/id\/doc_template_tag_tag_ifnotequal\" class=\"doc-reference doc-reference-tag\"><code>tag#ifnotequal<\/code><\/a>.<\/p><\/aside>\n<p>Show something if the condition is true.<\/p>\n<p>The <code>{% if %}<\/code> tag evaluates an expression 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-tag are output.<\/p>\n<div class=\"admonition note\"><p class=\"first admonition-title\">Note<\/p><p class=\"last\">Besides the <code>{% elif %}<\/code> tag we also support the alias <code>{% elseif %}<\/code>.<\/p><\/div>\n<p>If the if-test fails then the optional <code>{% elif %}<\/code> tags are evaluated. If both the if-test and all elif-tests fail, then the <code>{% else %}<\/code> tag contents are output.<\/p>\n<p>Example:<\/p>\n<pre class=\"notranslate\"><code class=\"notranslate language-django\">{% if genre == &quot;pop&quot; %}\n  Popular music.\n{% elif genre == &quot;classical&quot; %}\n  Classical music.\n{% elif genre == &quot;jazz&quot; %}\n  Jazz\n{% else %}\n  The genre isn&#39;t pop, classical or jazz.\n{% endif %}\n<\/code><\/pre>\n<p>An <code>{% if %}<\/code> and <code>{% elif %}<\/code> tag can have an “and” or “or” expression as argument:<\/p>\n<pre class=\"notranslate\"><code class=\"notranslate language-django\">{% if person_list and show_persons and full_moon %}\n  There are persons that we can show during full moon.\n{% endif %}\n<\/code><\/pre>\n<p>Or for example:<\/p>\n<pre class=\"notranslate\"><code class=\"notranslate language-django\">{% if new_moon or daytime %} Guess you can’t see the moon. {% endif %}\n<\/code><\/pre>\n<p>It is also possible to mix “and” and ”or” in one expression, so this is a valid:<\/p>\n<pre class=\"notranslate\"><code class=\"notranslate language-django\">{% if full_moon or daytime and cloudy %}\n<\/code><\/pre>\n<p>The evaluation order is: <code>and<\/code>, <code>xor<\/code>, and then <code>or<\/code>. Left to right associative. So the above is equivalent to:<\/p>\n<pre class=\"notranslate\"><code class=\"notranslate language-django\">{% if full_moon or (daytime and cloudy) %}\n<\/code><\/pre>\n<p>The ”not” operator can be used to negate a boolean value:<\/p>\n<pre class=\"notranslate\"><code class=\"notranslate language-django\">{% if full_moon or daytime or not clearsky %}\n<\/code><\/pre>\n<h2>if-with<\/h2>\n<p>The <code>if<\/code> is often combined with the <code>with<\/code> tag. For example:<\/p>\n<pre class=\"notranslate\"><code class=\"notranslate language-django\">{% with m.search[{latest cat=`news` pagelen=10}] as result %}\n    {% if result %}\n        &lt;h3&gt;{_ Latest news _}&lt;\/h3&gt;\n        &lt;ul&gt;\n          {% for id in result %}\n            &lt;li&gt;&lt;a href=&quot;{{ id.page_url }}&quot;&gt;{{ id.title }}&lt;\/a&gt;&lt;\/li&gt;\n          {% endfor %}\n        &lt;\/ul&gt;\n    {% endif %}\n{% endwith %}\n<\/code><\/pre>\n<p>To make this easier it is possible to combine the <code>if<\/code> and <code>with<\/code> tags in a single expression:<\/p>\n<pre class=\"notranslate\"><code class=\"notranslate language-django\">{% if m.search[{latest cat=`news` pagelen=10}] as result %}\n    &lt;h3&gt;{_ Latest news _}&lt;\/h3&gt;\n    &lt;ul&gt;\n      {% for id in result %}\n        &lt;li&gt;&lt;a href=&quot;{{ id.page_url }}&quot;&gt;{{ id.title }}&lt;\/a&gt;&lt;\/li&gt;\n      {% endfor %}\n    &lt;\/ul&gt;\n{% endif %}\n<\/code><\/pre>\n<p>The <code>as<\/code> can also be used in the <code>elif<\/code> expressions:<\/p>\n<pre class=\"notranslate\"><code class=\"notranslate language-django\">{% if expression1 as x %}\n  ...\n{% elif expression2 as y %}\n  ...\n{% else %}\n  ...\n{% endif %}\n<\/code><\/pre>","slug":"if","is_protected":false,"visible_for":0,"tz":"UTC","language":["en"],"doc_source_hash":"a9f353710b41450d57616c0b836963f85e33710c56872f309bae2ce2b120cbe6","is_featured":false,"content_group_id":{"id":2551,"is_a":["meta","content_group"],"name":"content_group_imported_docs","title":"Imported documentation","uri":"https:\/\/zotonic.com\/id\/content_group_imported_docs"},"category_id":{"id":324,"is_a":["meta","category"],"name":"template_tag","title":"Tags","uri":"https:\/\/test.zotonic.com\/id\/324"},"doc_source_path":"doc\/template-tags\/if.md","publication_start":"2023-06-24T08:17:53Z","github_url":"https:\/\/github.com\/zotonic\/zotonic\/blob\/master\/doc\/template-tags\/if.md","pivot_location_lng":null,"doc_source_kind":"template_tag","name":"doc_template_tag_tag_if","is_unfindable":false,"is_published":true,"pivot_geocode":null,"created":"2020-05-30T05:47:19Z","uri":null,"doc_status":"current","is_dependent":false,"publication_end":"9999-06-01T00:00:00Z","modifier_id":{"id":1,"is_a":["person"],"name":"administrator","title":"Site Administrator","uri":"https:\/\/zotonic.com\/id\/1"},"privacy":0,"doc_source_commit":"66cb145eae7002b184e7d8c4c7bba5e53e8248e5\n","creator_id":{"id":336,"is_a":["person","robot"],"name":"gitbot","title":"Git","uri":"https:\/\/zotonic.com\/id\/336"},"modified":"2026-10-02T12:40:49Z","title_slug":"if"},"uri":"https:\/\/zotonic.com\/id\/1364","uri_template":"https:\/\/zotonic.com\/id\/:id","websub":{"hub":"https:\/\/zotonic.com\/.zotonic\/websub","topic":"https:\/\/zotonic.com\/.zotonic\/websub\/topic\/1364"}},"status":"ok"}