0

I have Smarty enabled in settings file (on WordPress), and I am able to successfully use Smarty in Thank You letter template as long as I am using regular variables (non-arrays).

As soon as I try to create an array, I am unable to get it to work. Here are some things I have tried...

These simply display 1

<!--
{assign var="test" value=[111,222,333]}
-->
<p>{$test[2]}</p>

<!--
{assign var="test" value=[111,222,333]}
-->
<p>{$test.2}</p>

These create an error:

<!--
{assign var="test" value=['y'=>'yellow','b'=>'blue']} 
-->
<p>{$test[y]}</p>

<!--
{assign var="test" value=['y'=>'yellow','b'=>'blue']} 
-->
<p>{$test.y}</p>

EDIT: Just to add some more details on what I am doing... I am going to Find Contributions and then selecting All Records and then choosing Thank You Letters from the Actions drop down. I can successfully print a letter with ALL their contributions listed (each one individually), and I can successfully print a letter with a summary only Tax Deductible and/or Non Tax Deductible contributions. What I want to do is calculate a total for each Financial Type... I need to create an array in smarty in order add the total for each Financial Type seperately so I can then print a letter with a summary by Financial Type only. I am basing my solution on Iowa Boy answer from this thread: How to print USA tax receipt to individuals?

But regardless of my use case, I can not seem to get arrays in Smarty to work properly.

EDIT: So apparently Smarty v2 (currently the version used by CiviCRM) does NOT let you create or work with arrays.

2
  • Just a suggestion, but it might be helpful for others if you share the specific Civi use case you're trying to resolve by using arrays in the templates? Commented May 16, 2022 at 12:59
  • @LesleyCarter-BackOffice Okay, I have added more details.
    – jsherk
    Commented May 16, 2022 at 16:32

2 Answers 2

0

If you don't care about line-items and are just using the financial type at the contribution level, you should be able to use grouping by financial type as described here, using table cell: https://docs.civicrm.org/user/en/latest/contributions/manual-receipts-and-thank-yous/#grouped-contribution-thank-you-letters

Otherwise I don't think you can do arrays in smarty and the functions that might allow working around it will give a security error. But you could make a custom token in php.

3
  • So are you saying that arrays in Smarty are disabled in CiviCRM for security purposes? It's really irrelevent what I am trying to do besides create and use an array in Smarty in the Thank You message template. So if arrays just plain do not work, then that would be good information to mention somewhere in the docs so that others do not waste hours of their time trying to figure out why its not working.
    – jsherk
    Commented May 16, 2022 at 22:24
  • Smarty v2 doesn't let you create arrays directly (v3 does). Smarty v2 does have things like |explode to call arbitrary php functions but those are disabled for security reasons.
    – Demerit
    Commented May 16, 2022 at 22:46
  • It looks like current version of CiviCRM is using Smarty v2.6 so I guess no arrays then :( Thank you for clarifying
    – jsherk
    Commented May 17, 2022 at 2:05
0

CiviCRM v5.48.1 is using Smarty v2.6, and based on Demerit response above, it appears that Smarty v2 does not support arrays.

I am not sure if Smarty v2 (in any form) never supported arrays, or if it is just the implementation in CiviCRM that does not support arrays.

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.