1

I have burned hours on this and feel at a wall. Would appreciate some fresh eyes to shed light on new avenues of exploration.

I am using "find Contributions" to generate a list of contributions. I then choose "Thank you letters" and then choose the template I created.

In the template I am using some Smarty code that I found online last year that summarizes contributions and creates a neat table:

{foreach from=$contributions item=contribution} 
     {assign var="date" value=$contribution.receive_date|date_format:"%d %b %Y"}
    <tr>
        <td>{$date}</td>
        <td style="text-align:right;">${$contribution.total_amount|number_format:2:".":","}</td>
        <td>{$contribution.payment_instrument}{if $contribution.check_number neq""} - #{$contribution.check_number}{/if}</td>
        <td>{$contribution.campaign}</td>
        <td>{$contribution.contribution_source}</td>
    </tr>
{/foreach}
    <tr>
        <th>2020 TOTAL</th>
        <th style="text-align:right;">${$contribution_aggregate|number_format:2:".":","}</th>
        <th> </th>
        <th> </th>
        <th> </th>
    </tr>

It works great on one site producing a neat table: table output

However, on another site on the same server, I get "There has been a critical error on this website. Please check your site admin email inbox for instructions."

Checking the Apache error log I find a somewhat non-specific error:

[Wed Dec 23 13:51:44.466136 2020] [php7:error] [pid 31786] [client maskedIP:43002] PHP Fatal error:  Smarty error: [in string:&lt;table align=&quot;left&quot; border=&quot;1&quot; cellpadding=&quot;5&quot; cellspacing=&quot;0&quot; class=&quot;table&quot; style=&quot;margin-top:15px;&quot;&gt;\r\n\t&lt;tbody&gt;\r\n\t\t&lt;tr&gt;\r\n\t\t\t&lt;th&gt;Date&lt;/th&gt;\r\n\t\t\t&lt;th style=&quot;text-align:right;&quot;&gt;Amount&lt;/th&gt;\r\n\t\t\t&lt;th&gt;Method&lt;/th&gt;\r\n\t\t\t&lt;th&gt;Campaign&lt;/th&gt;\r\n\t\t\t&lt;th&gt;Note&lt;/th&gt;\r\n\t\t&lt;/tr&gt;\r\n\t\t&lt;!--\r\n    {foreach from=$contributions item=contribution} {assign\r\n    var=&quot;date&quot; value=$contribution.receive_date|date_format:&quot;%d %b\r\n    %Y&quot;}\r\n  --&gt;\r\n\t\t&lt;tr&gt;\r\n\t\t\t&lt;td&gt;{$date}&lt;/td&gt;\r\n\t\t\t&lt;td style=&quot;text-align:right;&quot;&gt;${$contribution.total_amount|number_format:2:&quot;.&quot;:&quot;,&quot;}&lt;/td&gt;\r\n\t\t\t&lt;td&gt;{$contribution.payment_instrument}{if $contribution.check_number neq&quot;&quot;} - #{$contribution.check_number}{/if}&lt;/td&gt;\r\n\t\t\t&lt;td&gt;{$contribution.campaign}&lt;/td&gt;\r\n\t\t\t&lt;td&gt;{$contribution.contri in /var/www/masked-url.org/wordpress/wp-content/plugins/civicrm/civicrm/packages/Smarty/Smarty.class.php on line 1100, referer: https://masked-url.org/wp-admin/admin.php?page=CiviCRM&q=civicrm%2Fcontribute%2Fsearch&_qf_PDFLetter_display=true&qfKey=bd001d277ba51fe3447c1acb3c2bed4dceb754c89022040c362d62bb4e04b4b3_9738

I have disabled entities in the CKEditor on both sites:

CKEditor settings

I have ensured Smarty is enabled in message templates and the error log confirms that because the error is clearly Smarty related.

I have literally cut-and-pasted the code from one site to the other and not changed it in any way.

I am able to do a very simple test successfully by putting the following code into a template:

<p>{$smarty.now|date_format}</p>
<p>{$smarty.version}</p>

I get valid output for that simple test on both sites:

enter image description here

I have also tried writing other Smarty code, but have had no luck getting anything other than that basic case to work. Likely that has at least something to do with my limited Smarty experience. However, the first code I shared works just great on one site and fails on the other.

Site 1 (works): WordPress 5.6, PHP 7.3.22, CiviCRM 5.30.0, Smarty 2.6.31 (though this seems very old so I expect it has been the CiviCRM version for a long time)

Site 2 (doesn't work - error above): WordPress 5.6, PHP 7.3.22, CiviCRM 5.32.2, Smarty 2.6.31

While the CiviCRM versions differ, I would hope that this is not a regression. It seems especially unlikely since the Smarty version has not changed.

Hoping someone can shed light or offer other places to look for useful logs that might provide a clue.

2
  • Not an ideal option but I would suggest you to change CiviCRM version to 5.30.0 - Sometime different version do make big difference - Thanks
    – Ramesh
    Dec 23, 2020 at 20:57
  • 1
    What I would do is add a line like CRM_Core_Error::debug_log_message($error_msg); just before line 1099 in packages/Smarty/Smarty.class.php and then you'll be able to see the full error and what it doesn't like by looking in ConfigAndLog.
    – Demerit
    Dec 23, 2020 at 21:51

2 Answers 2

2

Thanks to @demerit for suggesting a way to capture the full Smarty error in the log. I discovered that I was not getting the entire error in the Apache log. Using CRM_Core_Error::debug_log_message($error_msg); I was able to capture the entire error which included the following useful line:

 line 17]: [plugin] (secure mode) modifier 'number_format' is not allowed (Smarty_Compiler.class.php, line 1934)

Searching the web for that error revealed a post from Jan 2016 which showed that number_format is not supported, but one must use crmNumberFormat instead.

Making this replacement solved the problem. It remains a mystery why number_format works in another of my CiviCRM installations when it seems to have been an issue since at least 2016. However, that is a problem for another day. For now I am happy to have resolved the issue on this installation.

The corrected table is as follows:

<table align="left" border="1" cellpadding="5" cellspacing="0" class="table" style="margin-top:15px;">
<tbody>
    <tr>
        <th>Date</th>
        <th style="text-align:right;">Amount</th>
        <th>Method</th>
        <th>Campaign</th>
        <th>Note</th>
    </tr>
    <!--
{foreach from=$contributions item=contribution} {assign
var="date" value=$contribution.receive_date|date_format:"%d %b
%Y"}
-->
    <tr>
        <td>{$date}</td>
        <td style="text-align:right;">${$contribution.total_amount|crmNumberFormat:2:".":","}</td>
        <td>{$contribution.payment_instrument}{if $contribution.check_number neq""} - #{$contribution.check_number}{/if}</td>
        <td>{$contribution.campaign}</td>
        <td>{$contribution.contribution_source}</td>
    </tr>
    <!--
{/foreach}

-->
    <tr>
        <th>2019 TOTAL</th>
        <th style="text-align:right;">${$contribution_aggregate|crmNumberFormat:2:".":","}</th>
        <th>&nbsp;</th>
        <th>&nbsp;</th>
        <th>&nbsp;</th>
    </tr>
</tbody>
1

I've recently burned a lot of time on what looks like the same problem. For me it was a the CK editor persisting in browser cache, refusing to pickup updated configuration (which looks right in your screenshot).

Try different browser (or clean browser cache) and save the correct template again. Then test it. It should work.

1
  • A good thought, but unfortunately, I have already tried such measures over a number of days.
    – kapn
    Dec 28, 2020 at 14:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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