2

I'm using the "Thank-you letters - print or email" functionality to generate a receipt for contributions. I created a new template with all the information needed. However we have a problem to display the receipt date at the correct format. Actually, when I chose the token "Receipt date" in the combobox, Civi inserts {contribution.receipt_date} in my template, and when I generate a PDF, it displays the date with the hours : for example, "2019-02-25 16:01:00". We would just like to display the date (without the hours) at this format : dd/mm/YYYY (for example : "25/02/2019"). I tried to add code like "date_format" in the source of the template to change the date format, but it didn't work. Is there an easy way to change it ?

Thanks !

6

If you want 28 February 2019 {foreach from=$contributions item=contribution} {assign var="date" value=$contribution.receive_date|date_format:"%d %B %Y"}

If you want 28 02 2019 {foreach from=$contributions item=contribution} {assign var="date" value=$contribution.receive_date|date_format:"%d %m %Y"}

If you want it to look better (28/02/2019) you can add slashes value=$contribution.receive_date|date_format:"%d/%m/%Y"}

  • Thank you for your quick answer ! Am I supposed to put this code directly in the template (so in the civi interface) or in a file ? – Davum Mar 1 at 9:07
  • 1
    Correct, put it in the template. Admin > Communications > Message Templates. I assume there is already some Smarty code there. You will likely just need to edit that code to include the last part |date_format... – Iowa Boy Mar 1 at 16:23
  • Thank you for your answer again. I put the code ("|date_format...") in the message template, but it displays "{contribution.receipt_date|date_format:"%d %m %Y"}" when I generate the PDF instead of the value of the date. It's like it wasn't able to understand the smarty code... even though we're using smarty in other templates and it works properly. Have you any ideas of what I could have probably forgotten ? – Davum Mar 4 at 10:10
  • Where you have {contribution.receipt_date|date_format:"%d %m %Y"} should just have {date} the smarty is further up on your template. Look for something like {foreach from=$contributions item=contribution} {assign var="date" value=$contribution.receive_date} and add/edit the |date_format:"%d %m %Y" – Iowa Boy Mar 4 at 18:15
  • I think part of the confusion here is that {contribution.receipt_date}, i.e. "recei*pt*" and without the $ sign, is a token and smarty modifiers won't work on it, whereas {$contribution.receive_date}, i.e. "recei*v*e" and with the $ sign, is a variable available for use in the template, which you can use smarty modifiers on. – Demerit Mar 5 at 1:51

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.