Answers.Body: <p>Thanks for pasting the code: You can't use tokens inside a smarty command like that.</p>
  <p>You need to do:</p>
  <pre><code>{capture assign=pref}{contact.preferred_language}{/capture}
  {if $pref == &quot;fr_FR&quot;}OK{else}KO{/if}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-08-17T10:13:34.203Z
Answers.Text: Now getting "Mailing Error Expected a string or file resource" as error.
Answers.UserDisplayName: Pierre François
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-08-17T10:20:11.557Z
Answers.Text: Where do I have to insert the `{capture ...}` instruction? Into the body of the HTML text, into the plain text, or into the subject field. I need the variable `$pref` from the three places.
Answers.UserDisplayName: Pierre François
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-08-17T11:25:36.487Z
Answers.Text: There was als another problem: when I paste the smarty code into an HTML editor, the quotes are changed into entities `&quot;` that smarty doesn't recognise.
Answers.UserDisplayName: Pierre François
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-08-17T11:35:35.093Z
Answers.Text: There is a setting https://civicrm.stackexchange.com/questions/7212/escaping-quotes-in-ckeditor-breaks-smarty-syntax
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-08-16T17:48:35.347Z
Answers.LastActivityDate: 2021-08-16T17:48:35.347Z
Answers.UserDisplayName: Demerit
Body: <p>I try to send a single mail through Contacts &gt; New Mail using a template containing next Smarty instructions:</p>
  <pre><code>{if {contact.preferred_language} == &quot;fr_FR&quot;}OK{else}KO{/if}
  </code></pre>
  <p>but these mails cause an error with a very cryptic message:</p>
  <blockquote>
  <p>Error</p>
  <p>The website encountered an unexpected error. Please try again later.</p>
  </blockquote>
  <p>EDIT: Thanks to Demerit (see below), I could identify what is working and what not. The smarty code</p>
  <pre><code>{capture assign=pref}{contact.preferred_language}{/capture}
  
  {contact.email_greeting} ({contact.preferred_language} = {$pref}?),
  </code></pre>
  <p>is working as expected and gives the expected output</p>
  <blockquote>
  <p>Monsieur (fr_FR = fr_FR?),</p>
  </blockquote>
  <p>So, the <code>{capture}</code>instruction is working, but when I add the instruction below</p>
  <pre><code>{if $pref == &quot;fr_FR&quot;}OK{/if}
  </code></pre>
  <p>I get the error message described above and no message is sent.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-08-16T13:46:29.137Z
Comments.Text: Do you mind to paste your smarty code? may be there should be some syntax error in your smarty?
Comments.UserDisplayName: Pradeep Nayak
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-08-16T17:35:23.047Z
Comments.Text: @PradeepNayak: Sure, you are right: I should have done that before. I edited my question above to include the code causing the error.
Comments.UserDisplayName: Pierre François
Tags: <civimail>
Title: Is Smarty processing also available for sending single mails which are not a part of a mass mailing?
ThreadText: # Is Smarty processing also available for sending single mails which are not a part of a mass mailing?
  
  (Asked by: username_0 on 2021-08-16)
  
  I try to send a single mail through Contacts > New Mail using a template containing next Smarty instructions:
  {if {contact.preferred_language} == "fr_FR"}OK{else}KO{/if}
  
  but these mails cause an error with a very cryptic message:
  
  Error
  The website encountered an unexpected error. Please try again later.
  
  EDIT: Thanks to username_2 (see below), I could identify what is working and what not. The smarty code
  {capture assign=pref}{contact.preferred_language}{/capture}
  
  {contact.email_greeting} ({contact.preferred_language} = {$pref}?),
  
  is working as expected and gives the expected output
  
  Monsieur (fr_FR = fr_FR?),
  
  So, the {capture}instruction is working, but when I add the instruction below
  {if $pref == "fr_FR"}OK{/if}
  
  I get the error message described above and no message is sent.
  
  **Tags:** civimail
  
  > **Comments:**
  > **username_1**: Do you mind to paste your smarty code? may be there should be some syntax error in your smarty?  
  > **username_0**: @PradeepNayak: Sure, you are right: I should have done that before. I edited my question above to include the code causing the error.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2021-08-16. Score: 3 | Accepted answer
  
  Thanks for pasting the code: You can't use tokens inside a smarty command like that.
  You need to do:
  {capture assign=pref}{contact.preferred_language}{/capture}
  {if $pref == "fr_FR"}OK{else}KO{/if}
  
  > **Comments:**
  > **username_0**: Now getting "Mailing Error Expected a string or file resource" as error.  
  > **username_0**: Where do I have to insert the `{capture ...}` instruction? Into the body of the HTML text, into the plain text, or into the subject field. I need the variable `$pref` from the three places.  
  > **username_0**: There was als another problem: when I paste the smarty code into an HTML editor, the quotes are changed into entities `&quot;` that smarty doesn't recognise.  
  > **username_2**: There is a setting https://civicrm.stackexchange.com/questions/7212/escaping-quotes-in-ckeditor-breaks-smarty-syntax  
  
  ---
  
  