Answers.Body: <p>First - no need to enable Smarty system-wide to do this.  Greetings are always parsed by Smarty - see <a href="https://civicrm.org/blog/antrik/getting-started-with-new-name-and-greetings-features-in-45" rel="nofollow noreferrer">https://civicrm.org/blog/antrik/getting-started-with-new-name-and-greetings-features-in-45</a>.</p>
  
  <p>Besides that, I think you're one of the leading experts on complex token extensions, since you're the primary author of <a href="https://github.com/twomice/com.joineryhq.reltoken" rel="nofollow noreferrer">reltoken</a>.  But I don't see why you couldn't do this.  <code>hook_civicrm_tokenValues</code> gives you access to the token name for parsing, and there's no requirement that the token be listed with <code>hook_civicrm_tokens</code>.  So I'd say go for it.</p>
  
  <p>Note that this is similar but not identical to the free-form relative date work Eileen did: <a href="https://github.com/civicrm/civicrm-core/pull/12682" rel="nofollow noreferrer">https://github.com/civicrm/civicrm-core/pull/12682</a>.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-21T23:01:37.470Z
Answers.Text: Tokens are limited to [\w] characters, so any plan to use a non-word delimiter like `?` will have to involve changes in core. I'm concerned that will mushroom into something more than I want to undertake.
Answers.UserDisplayName: TwoMice
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-21T22:12:50.180Z
Answers.LastActivityDate: 2019-11-21T22:12:50.180Z
Answers.UserDisplayName: Jon G - Megaphone Tech
Body: <p>I want to provide a default value for tokens when the value is empty, on a per-use basis -- e.g., something like <code>{contact.first_name?Friend}</code> would print the contact's First Name if it's not empty, otherwise print "Friend".</p>
  
  <p><strong>Rationale update:</strong> This would allow non-programmers to easily specify a default value without needing to clutter up the tokens UI.</p>
  
  <p>Existing workarounds for this functionality are more cumbersome than that:</p>
  
  <ul>
  <li><a href="https://civicrm.org/blog/dave-greenberg/civimail-how-to-add-default-values-for-empty-tokens" rel="nofollow noreferrer">Dave's blog from version 2.2</a> uses hooks in an extension to hard-code defaults for specific tokens in all cases.</li>
  <li><a href="https://civicrm.stackexchange.com/a/23088/907">This SE answer</a> points out that this can be achieved by enabling Smarty processing and then inserting a few lines -- per token -- of Smarty code into the content.</li>
  </ul>
  
  <p>To avoid double-work and/or undertaking the impossible, I ask:</p>
  
  <p>Has any attempt been made to put such per-use-default-value functionality into CiviCRM core or an extension?</p>
  
  <p><strong>Technical challenges update:</strong> Tokens are limited to <code>\w</code> characters, so any plan to use a non-word delimiter like <code>?</code> will have to involve changes in core, as far as I can see.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-11-21T21:39:41.120Z
Comments.Text: I think the Smarty solution is simple enough. If you want it be on a per-use basis, I don't see how you can do it elsewhere without adding significant functionality to tokens.
Comments.UserDisplayName: Mick Kahn
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-11-22T08:20:05.263Z
Comments.Text: I do like your proposal.
Comments.UserDisplayName: Jaap Jansma - CiviCooP
Tags: <tokens>
Title: Empty token default values -- core or extension support?
ThreadText: # Empty token default values -- core or extension support?
  
  (Asked by: username_0 on 2019-11-21)
  
  I want to provide a default value for tokens when the value is empty, on a per-use basis -- e.g., something like `{contact.first_name?Friend}` would print the contact's First Name if it's not empty, otherwise print "Friend".
  
  **Rationale update:** This would allow non-programmers to easily specify a default value without needing to clutter up the tokens UI.
  
  Existing workarounds for this functionality are more cumbersome than that:
  
  * [Dave's blog from version 2.2](https://civicrm.org/blog/dave-greenberg/civimail-how-to-add-default-values-for-empty-tokens) uses hooks in an extension to hard-code defaults for specific tokens in all cases.
  * [This SE answer](https://civicrm.stackexchange.com/a/23088/907) points out that this can be achieved by enabling Smarty processing and then inserting a few lines -- per token -- of Smarty code into the content.
  
  To avoid double-work and/or undertaking the impossible, I ask:
  
  Has any attempt been made to put such per-use-default-value functionality into CiviCRM core or an extension?
  
  **Technical challenges update:** Tokens are limited to `\w` characters, so any plan to use a non-word delimiter like `?` will have to involve changes in core, as far as I can see.
  
  **Tags:** tokens
  
  > **Comments:**
  > **username_1**: I think the Smarty solution is simple enough. If you want it be on a per-use basis, I don't see how you can do it elsewhere without adding significant functionality to tokens.  
  > **username_2**: I do like your proposal.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_3 on 2019-11-21. Score: 3
  
  First - no need to enable Smarty system-wide to do this. Greetings are always parsed by Smarty - see <https://civicrm.org/blog/antrik/getting-started-with-new-name-and-greetings-features-in-45>.
  
  Besides that, I think you're one of the leading experts on complex token extensions, since you're the primary author of [reltoken](https://github.com/twomice/com.joineryhq.reltoken). But I don't see why you couldn't do this. `hook_civicrm_tokenValues` gives you access to the token name for parsing, and there's no requirement that the token be listed with `hook_civicrm_tokens`. So I'd say go for it.
  
  Note that this is similar but not identical to the free-form relative date work Eileen did: <https://github.com/civicrm/civicrm-core/pull/12682>.
  
  > **Comments:**
  > **username_0**: Tokens are limited to [\w] characters, so any plan to use a non-word delimiter like `?` will have to involve changes in core. I'm concerned that will mushroom into something more than I want to undertake.  
  
  ---
  
  