CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Tokens in System Workflow Message Templates not working
Pages: [1]

Author Topic: Tokens in System Workflow Message Templates not working  (Read 4532 times)

thomas.feichter

  • I’m new here
  • *
  • Posts: 10
  • Karma: 1
Tokens in System Workflow Message Templates not working
August 05, 2010, 01:05:26 am
I just tried to generate contribution receipts based on the preferred language of contacts.
It seems that several tokens are not replaced properly when generating PDF or mails even if they are set for the specified contact.
I was also able to reproduce it on drupal.demo.civicrm.org.

 
examples of tokens not being replaced properly:

contact.preferred_language
contact.postal_greeting
contact.email_greeting
contact.addressee
contact.preferred_communication_method


Furthermore when creating PDFs the following line appears in the PDF 'xmlns="http://www.w3.org/1999/xhtml">' it seems not to be rendered properly by dompdf.
Also the stripping of
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
 <title></title>
</head>
seems to cause problems with the encoding when using special characters like german umlauts.
see: CRM/Utils/PDF/Utils.php

        $htmlElementstoStrip = array(
                                     '@<head[^>]*?>.*?</head>@siu',
                                     '@<body>@siu',
                                     '@</body>@siu',
                                     '@</html>@siu',
                                     '@<!DOCTYPE[^>]*?>@siu',
                                     );


thx
tom

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Tokens in System Workflow Message Templates not working
August 05, 2010, 04:08:51 am
Yeah - I can imagine it would - I think I may have written that bit but I don't know what string I would use to deal with German characters
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Kurund Jalmi

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4169
  • Karma: 128
    • CiviCRM
  • CiviCRM version: 4.x, future
  • CMS version: Drupal 7, Joomla 3.x
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Tokens in System Workflow Message Templates not working
August 05, 2010, 05:29:38 am
I don't think CiviCRM translates tokens based on preferred language.

Kurund
Found this reply helpful? Support CiviCRM

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Tokens in System Workflow Message Templates not working
August 05, 2010, 02:32:04 pm
Hi Tom,

Do you want to try playing with the 'strip' stuff - I think I have this working on a 3.1.6 to get rid of the xmlns pdf bit - see                        '@<html[^>]*?>@siu',

But you can try not removing so much & see if dompdf will cope with your German language. At the moment it replaces:

Everything from <head to the final '>' and replaces with nothing - & so on for the other 5 items



Code: [Select]
$htmlElementstoStrip = array(
                        '@<head[^>]*?>.*?</head>@siu',
                        '@<body>@siu',
                        '@</body>@siu',
                        '@</html>@siu',
                        '@<html[^>]*?>@siu',
                        '@<!DOCTYPE[^>]*?>@siu',
                        );
                       

$htmlElementsInstead = array("","","","","");         
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Tokens in System Workflow Message Templates not working
August 05, 2010, 03:18:12 pm
Regarding the token replacement and use of tokens in smarty expressions for conditional flow control ....
1. We confirmed that the tokens you identified (and a few others) were NOT being populated / passed into the message template eval code. This has been fixed for 3.2.1. You can get a patch via Fisheye tab on this issue is you want to test sooner (which would be great): http://issues.civicrm.org/jira/browse/CRM-6600

2. I learned today from trying out your idea (exciting!)that you CAN use the CiviCRM contact tokens in smarty expressions. The trick is that you have to surround them with curly-brackets within the smarty expression (so brackets are nested).

For example, this works in a system message template (I used it in the Offline Contribution Receipt):
Code: [Select]
{if {contact.preferred_language} eq 'fr'}I see you speak french!{else}I see you speak some other language{/if}

CAVEAT: You'll need the CRM-6600 fix for the above example.

HOWEVER, I'm not sure what your environment is - but it seems like it would make sense to let the built-in translation {ts} functionality do it's job - at least for contributions submitted by the donor in an online contribution page where they can pick "their" language up front from the languages you've enabled in your site - and then they get things translated properly in the receipt.

Protect your investment in CiviCRM by  becoming a Member!

thomas.feichter

  • I’m new here
  • *
  • Posts: 10
  • Karma: 1
Re: Tokens in System Workflow Message Templates not working
August 06, 2010, 03:24:56 am
Thanks, I'll try the CRM-6600 fix.
Using the built-in translation {ts} functionality is not really working for me as we get many donations via bank transfer. For most of these transactions we don't have a related e-mail address, so we generate the contribution receipts and send them via postal mail. So far we did this using a custom field for the preferred language and using the exported data in MS Office.

The problem with german umlauts i solved by not stripping out the <head>...</head> part. But there seems to be another problem too since the € sign is still not encoded correctly. I'll try to figure that out next week. Is there a reason to strip out these elements? As far as I remember, dompdf normally renders these tags (<html>,<head>,<body>,...) without any problems.


One more problem i just realized on drupal.demo.civicrm.org (CiviCRM 28636):
when printing a contribution receipt for a € amount, the amount is shown in the PDF with the $ sign instead of €.

Thx
tom

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Tokens in System Workflow Message Templates not working
August 06, 2010, 02:38:58 pm
Don't know why we're stripping out those tags. Pending others posting here on that with more info, or if not you could test in various languages that it works WITH the tags and submit a patch to remove the stripping logic.

Regarding the currency symbol issues - please submit a bug report (preferably with a patch to fix).
Protect your investment in CiviCRM by  becoming a Member!

thomas.feichter

  • I’m new here
  • *
  • Posts: 10
  • Karma: 1
Re: Tokens in System Workflow Message Templates not working
August 09, 2010, 11:00:44 pm
I had now a closer look on the code and realized that the tags are stripped out of the template to avoid them appearing multiple times if more then one record is printed.
I solved this problem by stripping out the header and inserting it once into the html passed to dompdf. If there is no header specified, I use a default header.
See my patch file at http://issues.civicrm.org/jira/browse/CRM-6630.
I'm not very familiar with regex so these would probably need some revision to make them more fault tolerant when used with custom templates.
I also just realized that i forgot to include the <!DOCTYPE> tag, but it seems not to be required by dompdf.

My message template is now working (including CRM-6600 fix) and looking similar to the following:

Code: [Select]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
 <title></title>
</head>
<body>

{if '{contact.preferred_language}' eq 'de'}

<div style="margin: 120pt 54pt 54pt 54pt; font-family: Verdana; font-size: 10pt;">
  <div style="margin-left:300pt">
    {contact.addressee}
  </div>
  <p>Bozen, am {$smarty.now|date_format:'%d.%m.%Y'}</p>
  Some text in German...
</div>

{elseif '{contact.preferred_language}' eq 'it'}

<div style="margin: 120pt 54pt 54pt 54pt; font-family: Verdana; font-size: 10pt;">
  <div style="margin-left:300pt">
    {contact.addresse}
  </div>
  <p>Bolzano, il {$smarty.now|date_format:'%d.%m.%Y'}</p>
  Some text in Italian...
 
{elseif '{contact.preferred_language}' eq 'en'}
...
{else}
...
{/if}
</body>
</html>


I submitted a bug report regarding the currency symbol issue (http://issues.civicrm.org/jira/browse/CRM-6631)

resga

  • I post occasionally
  • **
  • Posts: 38
  • Karma: 3
  • CiviCRM version: 3.4.2
  • CMS version: Drupal
  • MySQL version: 5.1.41
  • PHP version: 5.3
Re: Tokens in System Workflow Message Templates not working
February 01, 2011, 07:28:21 am
This is still an issue, with the latest version(3.3.3) at drupal.demo.civicrm.org.

Quote
The problem with german umlauts i solved by not stripping out the <head>...</head> part.

I tried this, but perhaps not correctly, because if I have a user with a special character like æ, å or ø in their name, and select "Create Printable Letters (PDF)" it is printed like this "Ã…lice Ægdav".

Do you guys know how to fix this issue?
Thanks in advance!

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Tokens in System Workflow Message Templates not working
February 01, 2011, 09:55:20 am
You might want to start a new thread / repost this on the Internationalization board:
http://forum.civicrm.org/index.php/board,10.0.html
Protect your investment in CiviCRM by  becoming a Member!

resga

  • I post occasionally
  • **
  • Posts: 38
  • Karma: 3
  • CiviCRM version: 3.4.2
  • CMS version: Drupal
  • MySQL version: 5.1.41
  • PHP version: 5.3
Re: Tokens in System Workflow Message Templates not working
February 01, 2011, 10:36:15 am
Thanks Dave, I have posted it where you suggested.
CiviCRM is fast becoming my new favorite Open Source project :)

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Tokens in System Workflow Message Templates not working

This forum was archived on 2017-11-26.