Answers.Body: <p>There is no <code>{elif}</code> in smarty. Use <code>{elseif}</code>.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-15T11:43:43.650Z
Answers.Text: Gosh! Thank you.
Answers.UserDisplayName: Pierre François
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-14T19:16:22.083Z
Answers.LastActivityDate: 2021-03-14T19:16:22.083Z
Answers.UserDisplayName: Demerit
Body: <p>I have an Email greeting containing a Smarty if-then-else expression:</p>
  <pre><code>{capture assign=language}{contact.preferred_language}{/capture}{if $language == 'fr_FR'}Bonjour{elif $language == 'nl_NL'}Hallo{else}Hello (should be in '{$language}'){/if}
  </code></pre>
  <p>When the preferred language of the contact is <code>nl_NL</code>, I expect the expression above would output</p>
  <pre><code>Hallo
  </code></pre>
  <p>but I get</p>
  <pre><code>Hello (should be in 'nl_NL')
  </code></pre>
  <p>This shows that Smarty is activated and the variable <code>$language</code> is correctly assigned, but the test is failing.</p>
  <p>I would like to know what I am doing wrong.</p>
  
Tags: <smarty><civicontact>
Title: Smarty test fails in if-then-else
ThreadText: # Smarty test fails in if-then-else
  
  (Asked by: username_0 on 2021-03-14)
  
  I have an Email greeting containing a Smarty if-then-else expression:
  {capture assign=language}{contact.preferred_language}{/capture}{if $language == 'fr_FR'}Bonjour{elif $language == 'nl_NL'}Hallo{else}Hello (should be in '{$language}'){/if}
  
  When the preferred language of the contact is nl_NL, I expect the expression above would output
  Hallo
  
  but I get
  Hello (should be in 'nl_NL')
  
  This shows that Smarty is activated and the variable $language is correctly assigned, but the test is failing.
  I would like to know what I am doing wrong.
  
  **Tags:** smarty, civicontact
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-03-14. Score: 1 | Accepted answer
  
  There is no `{elif}` in smarty. Use `{elseif}`.
  
  > **Comments:**
  > **username_0**: Gosh! Thank you.  
  
  ---
  
  