I implemented miscellaneous custom tokens and have been using them successfully in mailings and pdf generation.

But in context of greetings I came across some weird misbehaviour. I tested by changing email greeting and running api job.update_greeting w/ force=1.

  1. When extending the token array's "contact" key with a custom token, the {contact.tokenname} markup get's interpreted but not replaced. Result is '{contact.tokenname}'.
  2. When using custom key the markup {keyname.tokenname} is not recognized and even doesn't get into the hook function's token parameter. Result is '' and Smarty reports »unrecognized tag«.

Both tokens run fine in pdf generation.

I'm running latest Drupal 7 and CiviCRM.

Any ideas?

Thanks in advance

  • Dear civi folks, am I missing something? Is this a dumb question?
    – nielo
    Aug 13, 2015 at 6:26
  • Today I investigated a bit and it seems that Tokens.php won't handle {contact.tokenname} because it doesn't get into it's self::$_tokens array. And {keyname.tokenname} won't get to replaceHookTokens because it's keyname is different to »contact«. Any ideas how to come around this?
    – nielo
    Aug 17, 2015 at 13:31

2 Answers 2


It sounds like the hook isn't being called (or not called correctly) when processing the update_greeting job. I think that qualifies as a bug and you could file it in issues.civicrm.org. But due to the high volume of issues, a core team member may not be available to jump on it anytime soon. I'd suggest you keep on with your debugging and compare the code that runs during that scheduled job to the code that correctly uses the hook and see how they differ. If you are able to come up with a patch that even partially addresses the problem it would help the issue get a lot more attention (issues with patches get bumped up in priority).


I filed an issue and kind of half-fixed it so that {customkey.tokenname} shaped tokens should work. If my approach is valid this may also fix Error for token.php related to greeting tokens

My issue: https://issues.civicrm.org/jira/browse/CRM-17038

  • Fix is being updated and handles tokens in contact category like {contact.tokenname} as well now.
    – nielo
    Aug 19, 2015 at 20:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.