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 »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Custom tokens not displaying in mailings
Pages: [1]

Author Topic: Custom tokens not displaying in mailings  (Read 665 times)

pminf

  • I post occasionally
  • **
  • Posts: 56
  • Karma: 0
  • CiviCRM version: 4.3
  • CMS version: Drupal 7
  • MySQL version: 5.6
  • PHP version: 5.3
Custom tokens not displaying in mailings
January 09, 2014, 05:36:57 am
Hi everyone,

I was happy to see, that there is the possibility to use custom tokens in mail templates to expand the standard CiviMail template functionality. Now I'm working for the whole day on this without displaying even the simpliest example. It's kind a frustrating so I hope you can help me a little bit on this before I loose my faith in CiviCRM.

I've tried to implement colemanw's custom token example (Create Your Own Tokens for Fun and Profit, under "Beyond Existing Tokens") without success. I've copypasted his code into my drupal modul and changed the function names. The hooks are executed successfully but the custom token is displayed as {date.date_short} instead of the correct date. To offer more details I'm pasting some watchdog output from my hooks in here:
Code: [Select]
/* Watchdog output in the last line of hook_civicrm_tokens */
// &tokens
Array
(
    [domain] =>
    [action] =>
    [mailing] =>
    [contact] =>
    [date] => Array
        (
            [date.date_short] => Today's Date: mm/dd/yyyy
            [date.date_med] => Today's Date: Mon d yyyy
            [date.date_long] => Today's Date: Month dth, yyyy
        )

)

/* Watchdog output in the last line of hook_civicrm_tokenValues */
// &values
Array
(
    [16946] => Array
        (
            [contact_id] => 16946
            [display_name] => John Doe
            [preferred_mail_format] => Both
            [hash] => 56321e3679c8dac40ae52c9d02fc23c9
            [is_deceased] => 0
            [email_id] => 11820
            [on_hold] => 0
        )

)
// &tokens
Array
(
    [domain] => Array
        (
            [address] => 1
        )

    [action] => Array
        (
            [optOutUrl] => 1
        )

)
// &context
CRM_Mailing_Page_Preview

As you can see, the array "tokens" does not contain the custom token, which was implement in "hook_civicrm_tokens" (so empty($tokens['date']) is always true). Even if I do not check if $tokens['date'] is empty, the custom token value does not show up in my mailings. I'm also wondering, why the &tokens array does contain the keys "domain" and "action".

Btw.: standard tokens like {contact.email} work as expected and it makes no difference, if I'm just sendung one single test mail or a large number via bulk mailing.

Edit #1: I have also tried to set CIVICRM_MAIL_SMARTY from 0 to 1 in civicrm.settings.php. This only results, that nothing is displayed (not even "{date.date_short}", just "").

Edit #2: If I send an e-mail directly to the contact (/civicrm/activity/email/add?action=add&reset=1&cid=16947&selectedChild=activity&atype=3), i get the right result (01/09/2014)! Hoooray! :) But using the custom token in bulk mailing templates still doesn't work :(

Any hint on this?

Thanks in advance
Philipp
« Last Edit: January 09, 2014, 08:24:43 am by PhilippMikael »

pminf

  • I post occasionally
  • **
  • Posts: 56
  • Karma: 0
  • CiviCRM version: 4.3
  • CMS version: Drupal 7
  • MySQL version: 5.6
  • PHP version: 5.3
Re: Custom tokens not displaying in mailings
January 09, 2014, 08:47:39 am
This is getting weird!

I've changed /sites/all/modules/civicrm/bin/cron.php as suggested here: http://forum.civicrm.org/index.php/topic,28989.msg124359.html#msg124359 and it workes! But after that I commented the newly added code out I also get the right results! Maybe it was just a coincidence and it wasn't the actual solution. The custom token is now even displaying in the online mailing preview. I thought those tokens would depend on the contact ( I'm wrong with that?), so I don't know why this is displaying in this general view. (edit: it's the personal view of my currently logged in user)
Btw.: I figured out, why &tokens array does contain the keys "domain" and "action". Those tokens are part of my mailing footers, which I totaly forgot about.

I'm now feeling like this cute little dog in front of a computer  ::)


« Last Edit: January 09, 2014, 11:16:40 pm by PhilippMikael »

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Custom tokens not displaying in mailings

This forum was archived on 2017-11-26.