The CiviCRM doumentation describes, how to use Smarty to customize templates for mails and pdf's:



{capture assign=gift}{contact.custom_16}{/capture}
{if $gift == Yes}
  This membership is a gift from {contact.custom_17}.


{capture assign=Anredestil}{contact.communication_style}{/capture}
<br/>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:&lt;p&gt;{capture assign=Anredestil}Du{/capture}&lt;
br /&gt;vielen Dank f&amp;uuml;r {if $Anredestil eq &amp;quot;Du&amp;quot;}Deine{else}Ihre{/if} Spende.&lt;/p&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

An obvious solution might be, to deactived the "secure mode" - however, this might create an unsafe situation.

2 Answers 2


After looking again I think this is ckeditor converting your smarty code to html. See also Escaping quotes in ckeditor breaks smarty-syntax


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}.

Good luck!

  • I think the docs might be wrong - the Yes is just missing quotes. You should be able to just do {if $gift == 'Yes'}
    – Demerit
    Commented Sep 25, 2020 at 19:42
  • @demerit: No, this not the solution in the case I mentioned! (I just double-checkecd...) Commented Sep 27, 2020 at 4:55
  • 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?
    – Demerit
    Commented Sep 27, 2020 at 5:10
  • Oh I wonder if this is ckeditor converting your smarty code to html internally. That's come up before. See civicrm.stackexchange.com/questions/7212/…
    – Demerit
    Commented Sep 28, 2020 at 14:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.