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) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Content with $ sign not printed correctly to PDF
Pages: [1]

Author Topic: Content with $ sign not printed correctly to PDF  (Read 905 times)

Siv

  • I post occasionally
  • **
  • Posts: 94
  • Karma: -17
  • CiviCRM version: 4.6.2
  • CMS version: Drupal 7.44
  • MySQL version: 5.5.24
  • PHP version: 5.3.13
Content with $ sign not printed correctly to PDF
October 13, 2014, 07:19:25 am
Am using message template to print some content to PDF. The content having amount with $ sign. The content printed to PDF correctly but amount not displayed correctly.
e.g : amount like $200.00 but displayed as 00.00

Is it issue with civicrm or am doing something wrong?

Thanks,
Siv

mathieu

  • Administrator
  • Ask me questions
  • *****
  • Posts: 620
  • Karma: 36
    • Work
  • CiviCRM version: 4.7
  • CMS version: Drupal
  • MySQL version: MariaDB 10
  • PHP version: 7
Re: Content with $ sign not printed correctly to PDF
October 14, 2014, 06:06:09 am
Hi,

I tested by going to a contact page, Action -> Print PDF Letter, then wrote "Test $200." in the message content, and generated the PDF. It worked as expected.

Which version of CiviCRM is it?
Can you reproduce on the demo site? https://civicrm.org/go/demo
Can you provide more details on the template content?

Thanks,
Mathieu
CiviCamp Montréal, 29 septembre 2017 | Co-founder / consultant / turn-key CiviCRM hosting for Quebec/Canada @ SymbioTIC.coop

Siv

  • I post occasionally
  • **
  • Posts: 94
  • Karma: -17
  • CiviCRM version: 4.6.2
  • CMS version: Drupal 7.44
  • MySQL version: 5.5.24
  • PHP version: 5.3.13
Re: Content with $ sign not printed correctly to PDF
October 14, 2014, 07:12:19 am
Thanks for your reply.

CiviCRM Version am using is : 4.3.5

Sample template content :  <div>{data.policy}</div>

It's working fine When i put content directly into the template but When i assign the content to variable and use it in template only getting this issue.

mathieu

  • Administrator
  • Ask me questions
  • *****
  • Posts: 620
  • Karma: 36
    • Work
  • CiviCRM version: 4.7
  • CMS version: Drupal
  • MySQL version: MariaDB 10
  • PHP version: 7
Re: Content with $ sign not printed correctly to PDF
October 14, 2014, 07:22:13 am
Seems like a custom token? People often write similar tokens, for example, to count the year-to-date donation amount. It should work.

Unless you can reproduce on the demo site, with the current version (4.5), I'm afraid that's asking a bit much from community support.

Good luck,
Mathieu
CiviCamp Montréal, 29 septembre 2017 | Co-founder / consultant / turn-key CiviCRM hosting for Quebec/Canada @ SymbioTIC.coop

Siv

  • I post occasionally
  • **
  • Posts: 94
  • Karma: -17
  • CiviCRM version: 4.6.2
  • CMS version: Drupal 7.44
  • MySQL version: 5.5.24
  • PHP version: 5.3.13
Re: Content with $ sign not printed correctly to PDF
October 15, 2014, 02:06:35 am
Civicrm running the below script for  replacing template variable by corresponding value.

preg_replace(http://php.net/manual/en/function.preg-replace.php) has special meaning for $n or ${n}. So that only number with $ replaced by preg_replace.
We can solve this issue by adding '\' before the $. Advice me if you have any other way to fix this in code itself.

$token = '\{data.policy(\|([^\}]+?))?\}'; // Template variable
$value = 'Amount: $15.00'; // Value for the template variable
$str = '<div>{data.policy}</div>'; // Template content
$str = preg_replace("/([^\{])?$token/", "\${1}$value", $str); // Replacing template variable by value

« Last Edit: October 15, 2014, 02:08:55 am by Siv »

Siv

  • I post occasionally
  • **
  • Posts: 94
  • Karma: -17
  • CiviCRM version: 4.6.2
  • CMS version: Drupal 7.44
  • MySQL version: 5.5.24
  • PHP version: 5.3.13
Re: Content with $ sign not printed correctly to PDF
November 10, 2014, 10:13:42 pm
Any help on this? :(

Michael McAndrew

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1274
  • Karma: 55
    • Third Sector Design
  • CiviCRM version: various
  • CMS version: Nearly always Drupal
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Content with $ sign not printed correctly to PDF
November 11, 2014, 01:03:08 am
So is this a token hook implementation?

Any chance you can link to / paste both hooks implementations in full to help people help you?
Service providers: Grow your business, build your reputation and support CiviCRM. Become a partner today

Siv

  • I post occasionally
  • **
  • Posts: 94
  • Karma: -17
  • CiviCRM version: 4.6.2
  • CMS version: Drupal 7.44
  • MySQL version: 5.5.24
  • PHP version: 5.3.13
Re: Content with $ sign not printed correctly to PDF
November 12, 2014, 05:15:47 am
No. It's not token hook implementation.
The below code to show how token replacement happening in civicrm.
eg:
Custom token used in my template is {data.policy} and the value is "Some text amount : $15.00".
Token replaced as "Some text amount : .00"  // $15 - removed

$token = '\{data.policy(\|([^\}]+?))?\}'; // Template variable
$value = 'Amount: $15.00'; // Value for the template variable
$str = '<div>{data.policy}</div>'; // Template content
$str = preg_replace("/([^\{])?$token/", "\${1}$value", $str); // Replacing template variable by value

Michael McAndrew

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1274
  • Karma: 55
    • Third Sector Design
  • CiviCRM version: various
  • CMS version: Nearly always Drupal
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Content with $ sign not printed correctly to PDF
November 17, 2014, 10:12:26 am
Quote
Custom token used in my template is {data.policy}

if this isn't coming via a hook, how is it getting there?!  In what file(s) is / are the code you have pasted below?
Service providers: Grow your business, build your reputation and support CiviCRM. Become a partner today

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Content with $ sign not printed correctly to PDF

This forum was archived on 2017-11-26.