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 CiviMail (Moderator: Piotr Szotkowski) »
  • Message template tokens
Pages: [1] 2

Author Topic: Message template tokens  (Read 7367 times)

palmquist

  • I post occasionally
  • **
  • Posts: 34
  • Karma: 2
  • CiviCRM version: 4.5.6
  • CMS version: Drupal 7.26
  • MySQL version: 5.5.36-log
  • PHP version: 5.4.24
Message template tokens
July 28, 2010, 03:24:36 pm
I am trying to customize one of the system workflow messages
(Home > CiviCRM > Administer CiviCRM > Message Templates > System Workflow Messages). 

From the errors my attempts have generated, it appears that the tokens which may be used in this type of message are not the same as the tokens described in the token documentation in the link which appears on the System Workflow Messages edit screen. 

For example {contact.first_name} returns an error. 

Most of the tokens in the default System Workflow Messages message I am trying to edit relate to $formValues but I can't seem to find a list of the available $formValues tokens.

Where can I find documentation for the tokens which are available in this context?

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Message template tokens
July 28, 2010, 07:29:13 pm

1. can u be more specific in what error is thrown when using: {contact.first_name}

2. The civicrm tokens are a fixed set (which u can find by clicking on the insert tokens list)

3. The $formValues array is not exposed as a civicrm token. In some cases we do expose the formValues array to smarty (as a smarty token). You can do a smartyDebug=1 on that page to see what smartyTokens are exposed to the user.

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

palmquist

  • I post occasionally
  • **
  • Posts: 34
  • Karma: 2
  • CiviCRM version: 4.5.6
  • CMS version: Drupal 7.26
  • MySQL version: 5.5.36-log
  • PHP version: 5.4.24
Re: Message template tokens
July 28, 2010, 09:21:42 pm
Thanks!  Somehow I hadn't noticed the "Insert Tokens" link, believe it or not!  ::)

The error message says "user error: Smarty error: [etc... duplicating many lines of the template here]
syntax error: unidentified token '.first_name' (Smarty_Compiler.class.php, line 1410) in /home1/.../sites/all/modules/civicrm/packages/Smarty/Smarty.class.php on line 1093."

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Message template tokens
July 28, 2010, 10:55:46 pm

1. can you cut-n-paste ALL your changes to the system template here

2. can you try to reproduce this on our 3.2 demo site (http://drupal.demo.civicrm.org/)

thanx

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

palmquist

  • I post occasionally
  • **
  • Posts: 34
  • Karma: 2
  • CiviCRM version: 4.5.6
  • CMS version: Drupal 7.26
  • MySQL version: 5.5.36-log
  • PHP version: 5.4.24
Re: Message template tokens
July 29, 2010, 11:56:38 am
Thanks for your help.  I made the same changes to the off-line contributions message on the demo site, and the same error appears, so hopefully that will make it easier to solve.

The changes to the system template are below (I only provided the text template below, but corresponding changes were made to the HTML template).

Is the problem that these tokens are not supported in the context of an if/else block?  That is my thought at this point.  If so, is there any way to accomplish such logic?

{if contact.email_greeting}
{contact.email_greeting},
{else}
{if contact.first_name}
Dear {contact.first_name},
{/if}
{/if}
{if $formValues.receipt_text}
{$formValues.receipt_text}
{else}
Thank you for your generous financial support. 
We will mail you a printed receipt soon, but in the meantime, you may print this message for your records if you need an immediate record.
{/if}


===========================================================
{ts}Contribution Information{/ts}

===========================================================
{ts}Contribution Type{/ts}: {$formValues.contributionType_name}
{if $lineItem}
{foreach from=$lineItem item=value key=priceset}
---------------------------------------------------------
{capture assign=ts_item}{ts}Item{/ts}{/capture}
{capture assign=ts_qty}{ts}Qty{/ts}{/capture}
{capture assign=ts_each}{ts}Each{/ts}{/capture}
{capture assign=ts_total}{ts}Total{/ts}{/capture}
{$ts_item|string_format:"%-30s"} {$ts_qty|string_format:"%5s"} {$ts_each|string_format:"%10s"} {$ts_total|string_format:"%10s"}
----------------------------------------------------------
{foreach from=$value item=line}
{$line.description|truncate:30:"..."|string_format:"%-30s"} {$line.qty|string_format:"%5s"} {$line.unit_price|crmMoney|string_format:"%10s"} {$line.line_total|crmMoney|string_format:"%10s"}
{/foreach}
{/foreach}
{/if}

{ts}Total Amount{/ts}: {$formValues.total_amount|crmMoney}
{if $receive_date}
{ts}Received Date{/ts}: {$receive_date|truncate:10:''|crmDate}
{/if}
{if $receipt_date}
{ts}Receipt Date{/ts}: {$receipt_date|truncate:10:''|crmDate}
{/if}
{if $formValues.paidBy and !$formValues.hidden_CreditCard}
{ts}Paid By{/ts}: {$formValues.paidBy}
{if $formValues.check_number}
{ts}Check Number{/ts}: {$formValues.check_number}
{/if}
{/if}
{if $formValues.trxn_id}
{ts}Transaction ID{/ts}: {$formValues.trxn_id}
{/if}

{if $ccContribution}
===========================================================
{ts}Billing Name and Address{/ts}

===========================================================
{$billingName}
{$address}

===========================================================
{ts}Credit Card Information{/ts}

===========================================================
{$credit_card_type}
{$credit_card_number}
{ts}Expires{/ts}: {$credit_card_exp_date|truncate:7:''|crmDate}
{/if}
{if $customGroup}
{foreach from=$customGroup item=value key=customName}
===========================================================
{$customName}
===========================================================
{foreach from=$value item=v key=n}
{$n}: {$v}
{/foreach}
{/foreach}
{/if}
{if $formValues.honor_first_name}

===========================================================
{$formValues.honor_type}
===========================================================
{$formValues.honor_prefix} {$formValues.honor_first_name} {$formValues.honor_last_name}
{if $formValues.honor_email}
{ts}Honoree Email{/ts}: {$formValues.honor_email}
{/if}
{/if}

{if $formValues.product_name}
===========================================================
{ts}Premium Information{/ts}

===========================================================
{$formValues.product_name}
{if $formValues.product_option}
{ts}Option{/ts}: {$formValues.product_option}
{/if}
{if $formValues.product_sku}
{ts}SKU{/ts}: {$formValues.product_sku}
{/if}
{if $fulfilled_date}
{ts}Sent{/ts}: {$fulfilled_date|crmDate}
{/if}
{/if}

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Message template tokens
July 29, 2010, 12:39:36 pm
Quote
Is the problem that these tokens are not supported in the context of an if/else block?  That is my thought at this point.  If so, is there any way to accomplish such logic?

Pretty sure that's the problem. The templates include 2 types of curly-bracketed entities - smarty variables which have leading $ (and can be used in conditional if/else statements) and tokens (which don't have the $ and are NOT smarty vars).

You can get a "dump" of the smarty variables that are available to you by adding this line anywhere in the template, and then triggering an offline receipt:
Code: [Select]
{debug}
The output will be part of the email receipt - encode in HTML so a bit hard to read in a text file - but manageable. I did a quick scan and it looks like the only contact name smarty var available is {$displayName} - looks like this in the debug output in the email:

Code: [Select]
<tr class=\"odd\">\n            <th>{$displayName}<\/th>\n            <td>&quot;Mrs Peter N Adams Jr&quot;<\/td><\/tr>
If you are developing / testing on this site you may want to direct all CiviCRM email output to a files on disk instead of actually sending them. Add this to your civicrm.settings.php file to change this behavior (NO EMAILS WILL BE SENT with this setting):

Code: [Select]
define( 'CIVICRM_MAIL_LOG' , 1 );
Emails will be written to files in sites/default/files/civicrm/templates_c/en_US/ConfigAndLog/mail directory.

Protect your investment in CiviCRM by  becoming a Member!

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Message template tokens (UPDATED INFO)
August 05, 2010, 03:01:05 pm
In the course of answering another post today and working with Lobo, I learned 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 will work in a system message template:
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 3.2.1 for the above example since we also discovered that some contact tokens were not being populated for System Message Templates. Patch available from: http://issues.civicrm.org/jira/browse/CRM-6600
Protect your investment in CiviCRM by  becoming a Member!

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: Message template tokens
August 05, 2010, 11:32:44 pm
3.2.1 out soon? there is another fix that we need, so wondering if we patch or wait - thanks for sorting these so quickly
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

Piotr Szotkowski

  • Moderator
  • I live on this forum
  • *****
  • Posts: 1497
  • Karma: 57
Re: Message template tokens
August 06, 2010, 03:39:33 am
Quote from: peterd on August 05, 2010, 11:32:44 pm
3.2.1 out soon?

Hopefully next week, maybe the week after – depending on how the 3.2.1 issue queue looks like.
If you found the above helpful, please consider helping us in return – you can even steer CiviCRM’s future and help us extend CiviCRM in ways useful to you.

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: Message template tokens
May 11, 2011, 10:02:22 am
Code: [Select]
{if {contact.preferred_language} eq 'fr'}I see you speak french!{else}I see you speak some other language{/if} doesn't seem to work in either version 3.3 or 3.4. If I try to insert it in a Printable Letter (PDF) I get the following error message:

Version 3.3: Parse error: syntax error, unexpected '&' in sites/default/files/civicrm/templates_c/en_US/da_DK/%%E6/E66/E66937BB%%p%3E.php on line 3

Version 3.4: Parse error: syntax error, unexpected '&' in sites/default/files/civicrm/templates_c/en_US/da_DK/%%2E/2E1/2E1324E4%%p%3E.php on line 3

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Message template tokens
May 11, 2011, 01:36:14 pm

can u reproduce this on our demo server. the error message seems wierd

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Message template tokens
May 11, 2011, 01:49:34 pm
resga - Sorry for some confusion - we missed that you were doing this in the PDF Letter context.

In order to use smarty syntax in PDF Letter and Send Email to Contacts you need to explicitly enable it by adding this constant to your civicrm.settings.php file:

 define( 'CIVICRM_MAIL_SMARTY', 1 );

(You may already have this constant with a value of 0 if you installed the 3.4.1 from scratch - otherwise you'll need to add it.)
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: Message template tokens
May 11, 2011, 02:13:22 pm
Lobo: On the Demo server(V. 3.4) I get this error:
  Sorry. A non-recoverable error has occurred.
  PDF Format Option Group not found in database.

Dave: Thanks for checking, but I do have Smarty Templates enabled the define( 'CIVICRM_MAIL_SMARTY', 1 ); in the civicrm.settings.php file. The error does seem weird. The folder sites/default/files/civicrm/templates_c/en_US/ is full of folders with names like %%OB, %%OC, %%0F, and so on, 120 all in all. And then also the da_DK folder, with 250 folders in the same style. But perhaps that's how it is supposed to be?

I am using Danish as default language, might that be causing the error?

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Message template tokens
May 11, 2011, 04:49:48 pm

the demo server is giving errors since we merged some 3.4.2 code in there. We'll fix it in the next day or so

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

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: Message template tokens
May 12, 2011, 01:31:21 am
That sounds great Lobo!

Forgive me if I haven't understood the purpose of the demo server, but is it a good idea to use it for testing new code live? I would think the best practice was to have a stable demo version on-line, also so that new users have a good first time experience, when trying the demo version. I also wouldn't like to use a beta version for production, which I might need to, if the Smarty code above does work in the current 3.4.2 version, and not the recommended stable version, 3.4.1.

But perhaps that is the purpose of the demo server, part presentation, part sandbox?

About the error, might it have something to do with php version 5.2 versus 5.3? I have stumbled over other places in the Drupal world where the added ampersand-sign("&") in variables messes up in 5.3 or in 5.2 I forget...
For example &$variable_name versus $variable_name, without the ampersand-sign.
« Last Edit: May 12, 2011, 01:52:42 am by resga »

Pages: [1] 2
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviMail (Moderator: Piotr Szotkowski) »
  • Message template tokens

This forum was archived on 2017-11-26.