Answers.Body: <p>After looking again I think this is ckeditor converting your smarty code to html. See also <a href="https://civicrm.stackexchange.com/questions/7212/escaping-quotes-in-ckeditor-breaks-smarty-syntax">Escaping quotes in ckeditor breaks smarty-syntax</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-09-29T13:37:00.910Z
Answers.LastActivityDate: 2020-09-29T13:37:00.910Z
Answers.UserDisplayName: Demerit
Answers.Body: <p>There is a surprisingly simple solution:</p>
  <p>Smarty assumes, that comparison containing a constant string is unsafe.
  A remedy is, to assign the constant value to a variable, and to perform the comparison between these two variables.</p>
  <p>The code example from above could look like:</p>
  <pre><code>{capture assign=gift}{contact.custom_16}{/capture}
  {capture assign=Yes}Yes{/capture}
  {if $gift == $Yes}
    This membership is a gift from {contact.custom_17}.
  {/if}
  </code></pre>
  <p>Good luck!</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-09-25T19:42:57.920Z
Answers.Text: I think the docs might be wrong - the Yes is just missing quotes. You should be able to just do `{if $gift == 'Yes'}`
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-09-27T04:55:47.607Z
Answers.Text: @demerit: No, this not the solution in the case I mentioned! 
  (I just double-checkecd...)
Answers.UserDisplayName: Detlev Sieber
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-09-27T05:10:48.007Z
Answers.Text: Ok looking at your fatal error again it seems to be `<p>{capture assign=Anredestil}Du{/capture}<br />vielen Dank f&ur {if $Anredestil eq &"Du&"}Deine{else}Ihre{/if} Spende.</p>` - is there a reason you have `&` in there? Is that part of your original smarty code?
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-09-28T14:57:37.513Z
Answers.Text: Oh I wonder if this is ckeditor converting your smarty code to html internally. That's come up before. See 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: 2020-09-25T18:59:11.063Z
Answers.LastActivityDate: 2020-09-25T18:59:11.063Z
Answers.UserDisplayName: Detlev Sieber
Body: <p>The CiviCRM doumentation describes, how to use Smarty to customize templates for mails and pdf's:</p>
  <p><a href="https://docs.civicrm.org/user/en/latest/common-workflows/tokens-and-mail-merge/#smarty" rel="nofollow noreferrer">https://docs.civicrm.org/user/en/latest/common-workflows/tokens-and-mail-merge/#smarty</a></p>
  <p>E.g.:</p>
  <pre><code>{capture assign=gift}{contact.custom_16}{/capture}
  {if $gift == Yes}
    This membership is a gift from {contact.custom_17}.
  {/if}
  </code></pre>
  <p>Or:</p>
  <pre><code>{capture assign=Anredestil}{contact.communication_style}{/capture}
  &lt;br/&gt;vielen Dank für 
  {if $Anredestil eq 'Du'}Deine{else}Ihre{/if}
  </code></pre>
  <p>However, in certain conditions (especially but not limited to CiviCRM on Wordpress), this creates fatal errors like:</p>
  <pre><code>PHP Fatal error:  Smarty error: [in string:&amp;lt;p&amp;gt;{capture assign=Anredestil}Du{/capture}&amp;lt;
  br /&amp;gt;vielen Dank f&amp;amp;uuml;r {if $Anredestil eq &amp;amp;quot;Du&amp;amp;quot;}Deine{else}Ihre{/if} Spende.&amp;lt;/p&amp;gt; line 1]: syntax error: (secure mode) 'quot' not allowed in if statement (Smarty_Compiler.class.php, line 1399) in /html/wordpress/wp-content/plugins/c
  ivicrm/civicrm/packages/Smarty/Smarty.class.php on line 1100
  </code></pre>
  <p>An obvious solution might be, to deactived the &quot;secure mode&quot; - however, this might create an unsafe situation.</p>
  
Tags: <wordpress><smarty><templates>
Title: PHP Fatal error: Smarty error: [in string: (...)]: syntax error: (secure mode) (...) not allowed in if statement (...)
ThreadText: # PHP Fatal error: Smarty error: [in string: (...)]: syntax error: (secure mode) (...) not allowed in if statement (...)
  
  (Asked by: username_0 on 2020-09-25)
  
  The CiviCRM doumentation describes, how to use Smarty to customize templates for mails and pdf's:
  https://docs.civicrm.org/user/en/latest/common-workflows/tokens-and-mail-merge/#smarty
  E.g.:
  {capture assign=gift}{contact.custom_16}{/capture}
  {if $gift == Yes}
    This membership is a gift from {contact.custom_17}.
  {/if}
  
  Or:
  {capture assign=Anredestil}{contact.communication_style}{/capture}
  vielen Dank für 
  {if $Anredestil eq 'Du'}Deine{else}Ihre{/if}
  
  However, in certain conditions (especially but not limited to CiviCRM on Wordpress), this creates fatal errors like:
  PHP Fatal error:  Smarty error: [in string:<p>{capture assign=Anredestil}Du{/capture}<
  br />vielen Dank f&uuml;r {if $Anredestil eq &quot;Du&quot;}Deine{else}Ihre{/if} Spende.</p> line 1]: syntax error: (secure mode) 'quot' not allowed in if statement (Smarty_Compiler.class.php, line 1399) in /html/wordpress/wp-content/plugins/c
  ivicrm/civicrm/packages/Smarty/Smarty.class.php on line 1100
  
  An obvious solution might be, to deactived the "secure mode" - however, this might create an unsafe situation.
  
  **Tags:** wordpress, smarty, templates
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2020-09-29. Score: 2
  
  After looking again I think this is ckeditor converting your smarty code to html. See also [Escaping quotes in ckeditor breaks smarty-syntax](https://civicrm.stackexchange.com/questions/7212/escaping-quotes-in-ckeditor-breaks-smarty-syntax)
  
  
  ---
  
  ### Answer by username_0 on 2020-09-25. Score: 0
  
  There is a surprisingly simple solution:
  Smarty assumes, that comparison containing a constant string is unsafe.
  A remedy is, to assign the constant value to a variable, and to perform the comparison between these two variables.
  The code example from above could look like:
  {capture assign=gift}{contact.custom_16}{/capture}
  {capture assign=Yes}Yes{/capture}
  {if $gift == $Yes}
    This membership is a gift from {contact.custom_17}.
  {/if}
  
  Good luck!
  
  > **Comments:**
  > **username_1**: I think the docs might be wrong - the Yes is just missing quotes. You should be able to just do `{if $gift == 'Yes'}`  
  > **username_0**: @demerit: No, this not the solution in the case I mentioned!  (I just double-checkecd...)  
  > **username_1**: Ok looking at your fatal error again it seems to be `<p>{capture assign=Anredestil}Du{/capture}<br />vielen Dank f&ur {if $Anredestil eq &"Du&"}Deine{else}Ihre{/if} Spende.</p>` - is there a reason you have `&` in there? Is that part of your original smarty code?  
  > **username_1**: Oh I wonder if this is ckeditor converting your smarty code to html internally. That's come up before. See https://civicrm.stackexchange.com/questions/7212/escaping-quotes-in-ckeditor-breaks-smarty-syntax  
  
  ---
  
  