{"result":{"depiction_url":null,"edges":{"in_module":{"objects":[{"created":"2020-05-30T05:48:15Z","object_id":{"id":1296,"is_a":["text","documentation","reference","module"],"name":"doc_module_mod_base","title":"mod_base","uri":"https:\/\/zotonic.com\/id\/1296"},"seq":1000000}],"predicate":{"id":333,"is_a":["meta","predicate"],"name":"in_module","title":{"_type":"trans","tr":{"en":"In module"}},"uri":"https:\/\/zotonic.com\/id\/in_module"}},"references":{"objects":[{"created":"2020-05-30T05:48:15Z","object_id":{"id":1364,"is_a":["text","documentation","reference","template_tag"],"name":"doc_template_tag_tag_if","title":"if","uri":"https:\/\/zotonic.com\/id\/1364"},"seq":1000000}],"predicate":{"id":332,"is_a":["meta","predicate"],"name":"references","title":{"_type":"trans","tr":{"en":"References"}},"uri":"https:\/\/zotonic.com\/id\/references"}},"refers":{"objects":[{"created":"2026-09-09T13:48:06Z","object_id":{"id":1364,"is_a":["text","documentation","reference","template_tag"],"name":"doc_template_tag_tag_if","title":"if","uri":"https:\/\/zotonic.com\/id\/1364"},"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:15Z","object_id":{"id":1364,"is_a":["text","documentation","reference","template_tag"],"name":"doc_template_tag_tag_if","title":"if","uri":"https:\/\/zotonic.com\/id\/1364"},"seq":1000000},{"created":"2020-05-30T05:48:15Z","object_id":{"id":1846,"is_a":["text","documentation","reference","template_filter"],"name":"doc_template_filter_filter_if_undefined","title":"if_undefined","uri":"https:\/\/zotonic.com\/id\/1846"},"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:06Z","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:06Z","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:06Z","object_id":{"id":2621,"is_a":["categorization","keyword","keyword_architecture"],"name":"zotonic_topic_template_filter","title":"Template filter","uri":"https:\/\/zotonic.com\/id\/2621"},"seq":3},{"created":"2026-09-09T13:48:06Z","object_id":{"id":2649,"is_a":["categorization","keyword","keyword_task"],"name":"zotonic_topic_compare","title":"Compare","uri":"https:\/\/zotonic.com\/id\/2649"},"seq":4},{"created":"2026-09-09T13:48:06Z","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":1849,"is_a":["text","documentation","reference","template_filter"],"links":[{"rel":"self","target":"https:\/\/zotonic.com\/.zotonic\/websub\/topic\/1849"},{"rel":"hub","target":"https:\/\/zotonic.com\/.zotonic\/websub"}],"medium":null,"medium_url":null,"name":"doc_template_filter_filter_if","page_url":{"en":"https:\/\/zotonic.com\/docs\/1849\/if","x-default":"https:\/\/zotonic.com\/docs\/1849\/if"},"preview_url":null,"resource":{"version":4066,"pivot_location_lat":null,"title":"if","is_authoritative":true,"body":"<p>Selects an argument depending on a condition.<\/p>\n<p>For example:<\/p>\n<pre class=\"notranslate\"><code class=\"notranslate language-django\">{{ value|if:&quot;yes&quot;:&quot;no&quot; }}\n<\/code><\/pre>\n<p>This is a shortcut for using the <a href=\"\/id\/doc_template_tag_tag_if\" class=\"doc-reference doc-reference-tag\"><code>tag#if<\/code><\/a> tag. The same can be expressed as follows:<\/p>\n<pre class=\"notranslate\"><code class=\"notranslate language-django\">{% if value %}yes{% else %}no{% endif %}\n<\/code><\/pre>\n<p>Note that falsy values (0, <code>false<\/code>, <code>undefined<\/code> or empty string) evaluate to false.<\/p>\n<p>In templates, the compiler evaluates the condition once and only evaluates the\nselected argument. The other argument is not evaluated, so a model lookup in\nthat branch does not run. Both arguments are required; use <code>undefined<\/code> when the\nfalse branch should produce no value.<\/p>\n<p>Combine the filter with <code>as<\/code> to reuse the selected value:<\/p>\n<pre class=\"notranslate\"><code class=\"notranslate language-django\">{% if show_image|if:m.media[id]:undefined as medium %}\n    {{ medium.mime|escape }}\n{% endif %}\n<\/code><\/pre>\n<p>The media model is only queried when <code>show_image<\/code> is true. The block is rendered\nwhen the selected value is truthy, and <code>medium<\/code> contains that value.<\/p>\n<p>This lazy evaluation applies to compiled templates. Direct Erlang calls to\n<code>filter_if:&#39;if&#39;\/4<\/code> follow normal Erlang evaluation: all arguments are evaluated\nbefore the function is called.<\/p>\n<h2>Elaborate examples<\/h2>\n<pre class=\"notranslate\"><code class=\"notranslate language-django\">{% with is_i18n|if:r.translation[lang_code].body:r.body as body %}\n<\/code><\/pre>\n<p>So if <code>is_i18n<\/code> evaluates to true, <code>body<\/code> is assigned to <code>r.translation[lang_code].body<\/code>, else to <code>r.body<\/code>.<\/p>\n<pre class=\"notranslate\"><code class=\"notranslate language-django\">{% include &quot;_language_attrs.tpl&quot; id=pid class=(pid==id)|if:&quot;active&quot;:&quot;&quot; %}\n<\/code><\/pre>\n<p>Add parameter <code>class<\/code> to the included template; when <code>pid<\/code> equals <code>id<\/code>, <code>class<\/code> is <code>&quot;active&quot;<\/code>, otherwise an empty string.<\/p>","slug":"if","is_protected":false,"visible_for":0,"tz":"UTC","language":["en"],"doc_source_hash":"5e66b1e866ad2b99ff087db1041a82beba3a530550cb3b2b0afa745eec351329","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":325,"is_a":["meta","category"],"name":"template_filter","title":"Filters","uri":"https:\/\/test.zotonic.com\/id\/325"},"doc_source_path":"apps\/zotonic_mod_base\/src\/filters\/filter_if.erl","publication_start":"2023-06-24T08:18:02Z","github_url":"https:\/\/github.com\/zotonic\/zotonic\/blob\/master\/apps\/zotonic_mod_base\/src\/filters\/filter_if.erl","pivot_location_lng":null,"doc_source_kind":"filter","name":"doc_template_filter_filter_if","is_unfindable":false,"is_published":true,"pivot_geocode":null,"created":"2020-05-30T05:47:39Z","uri":null,"doc_status":"current","is_dependent":false,"erlang_app":"zotonic_mod_base","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":"7df977519c8cf191b758d30a0ddca1826a013903\n","erlang_module":"filter_if","creator_id":{"id":336,"is_a":["person","robot"],"name":"gitbot","title":"Git","uri":"https:\/\/zotonic.com\/id\/336"},"modified":"2026-10-22T13:33:27Z","title_slug":"if"},"uri":"https:\/\/zotonic.com\/id\/1849","uri_template":"https:\/\/zotonic.com\/id\/:id","websub":{"hub":"https:\/\/zotonic.com\/.zotonic\/websub","topic":"https:\/\/zotonic.com\/.zotonic\/websub\/topic\/1849"}},"status":"ok"}