0

Since I enabled Smarty 3 under CiviCRM 5.72, the messages containing dates followed by the |date_format:"%e/%m/%Y" modifier cause next error message to occur:

There has been a critical error on this website.

I tried to use the |crmDate:"%e/%m/%Y" modifier instead but I get the same error message.

I wonder how I could format dates in my messages with Smarty 3, or shall I seriously have to downgrade to Smarty 2 forever?

1 Answer 1

1

date_format is deprecated because strftime is deprecated in php 8. The problem with crmDate is the input has to be in ISO format, but it might not be depending on your site settings.

But in smarty 3 you have the option of telling date_format to use the non-deprecated date instead of strftime, but note that the format specifiers are different and do not have % in them. In fact that's how you tell it, by leaving out the %. So try |date_format:"j/m/Y". EDIT: This should work but fails because there's still some intermediate code in core that ends up trying to load smarty2 date_format. If I hack this line to instead be $smartyDir = $pkgsDir . DIRECTORY_SEPARATOR . 'smarty4/vendor/smarty/smarty/libs' . DIRECTORY_SEPARATOR; and then clear cache, then it works.

Also by the way, for 5.72+ the recommended smarty is now v4: https://github.com/civicrm/civicrm-core/blob/bcac045c1317be9be2a5db0c46bfd5354cd34985/templates/CRM/common/civicrm.settings.php.template#L267

6
  • Changing the format string in date_format + changing one line in wp-content/plugins/civicrm/civicrm/CRM/Core/Smarty.php + clearing the cache with the command wp cache flush did the trick. Thank you. Commented Apr 6 at 17:37
  • I have a question: will I have to change manually that one line in wp-content/plugins/civicrm/civicrm/CRM/Core/Smarty.php at each update of CiviCRM core? Commented Apr 6 at 17:39
  • 1
    No it will need to be fixed in core. I made a ticket lab.civicrm.org/dev/core/-/issues/5130
    – Demerit
    Commented Apr 6 at 18:24
  • It looks like as of 5.73.0, Civi core has been updated so no "hack" is needed, right? Commented May 23 at 19:54
  • Core itself replaced date_format in message templates a long time ago before knowing about the smarty3/4 feature. So this question only applies if you are using a customized message template that has date_format in it. If you do, then upon upgrading to 5.73, your options are: (1) Continue to use date_format, but you'll need to both switch to smarty 4, and update the format strings in your template to the non-% version. (2) Use crmDate, which in some locales doesn't parse the input properly, so won't output what you want. crmDate only works reliably when the input is ISO format.
    – Demerit
    Commented May 23 at 20:21

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