Answers.Body: <p>Those are Smarty templates, and don't use regular CiviCRM tokens - which is confusing because the tokens can look the same.</p>
  <p>Fortunately, Smarty is a full-fledged templating language.  You can do <a href="https://www.smarty.net/docsv2/en/language.modifier.date.format" rel="nofollow noreferrer">date formatting</a> pretty easily.  I think you want this:</p>
  <pre><code>{$smarty.now|date_format:&quot;%Y&quot;}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-23T13:57:31.690Z
Answers.Text: Unfortunately this does not work for me. Smarty seems not to be interpreted either, although I have enabled it in civicrm.settings.php with `define( 'CIVICRM_MAIL_SMARTY', 1 );` and clearing cache afterwards. Are you sure this works within the "Subscribe Message"?
Answers.UserDisplayName: Philipp Michael
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-23T10:55:25.263Z
Answers.LastActivityDate: 2020-10-23T10:55:25.263Z
Answers.UserDisplayName: Jon G - Megaphone Tech
Body: <p>I'm trying to privide a token for mailing related automated messages. I followed the instructions about <code>hook_civicrm_tokens</code> and <code>hook_civicrm_tokenValues</code> but it does only work for &quot;CiviMail&quot; mails. In mails for group subscriptions (at least &quot;Subscribe Message&quot;, &quot;Resubscribe Message&quot;, &quot;Unsubscribe Message&quot; and &quot;Welcome Message&quot;) the custom token will not be replaced.</p>
  <pre><code>function mysite_civicrm_tokens(&amp;$tokens){
    // Define tokens for date (like today's year)
    $tokens['date'] = [
      'date.year' =&gt; ts(&quot;Today's Date: year&quot;)
    ];
  }
  
   function mysite_civicrm_tokenValues(&amp;$values, $cids, $job = null, $tokens = [], $context = null) {
    // Set tokens values for date
    if(isset($tokens['date'])) {
      // TODO: Check if token is required.
      foreach ($cids as $cid) {
        $values[$cid]['date.year'] = date(&quot;Y&quot;);
      }
    }
  }
  </code></pre>
  <p>The custom token defined in <code>mysite_civicrm_tokens</code> is not availible in <code>mysite_civicrm_tokenValues</code> although I have placed it inside the mailing components under <em>civicrm/admin/component</em>.</p>
  <p>I know that those mails are handled different from CiviMail mails so I guess there might be another way to solve this.</p>
  
Tags: <tokens><hooks><message-templates><subscribe>
Title: How to provide custom token for subscription related automated messages?
ThreadText: # How to provide custom token for subscription related automated messages?
  
  (Asked by: username_0 on 2020-10-22)
  
  I'm trying to privide a token for mailing related automated messages. I followed the instructions about hook_civicrm_tokens and hook_civicrm_tokenValues but it does only work for "CiviMail" mails. In mails for group subscriptions (at least "Subscribe Message", "Resubscribe Message", "Unsubscribe Message" and "Welcome Message") the custom token will not be replaced.
  function mysite_civicrm_tokens(&$tokens){
    // Define tokens for date (like today's year)
    $tokens['date'] = [
      'date.year' => ts("Today's Date: year")
    ];
  }
  
   function mysite_civicrm_tokenValues(&$values, $cids, $job = null, $tokens = [], $context = null) {
    // Set tokens values for date
    if(isset($tokens['date'])) {
      // TODO: Check if token is required.
      foreach ($cids as $cid) {
        $values[$cid]['date.year'] = date("Y");
      }
    }
  }
  
  The custom token defined in mysite_civicrm_tokens is not availible in mysite_civicrm_tokenValues although I have placed it inside the mailing components under civicrm/admin/component.
  I know that those mails are handled different from CiviMail mails so I guess there might be another way to solve this.
  
  **Tags:** tokens, hooks, message-templates, subscribe
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-10-23. Score: 1
  
  Those are Smarty templates, and don't use regular CiviCRM tokens - which is confusing because the tokens can look the same.
  Fortunately, Smarty is a full-fledged templating language.  You can do date formatting pretty easily.  I think you want this:
  {$smarty.now|date_format:"%Y"}
  
  > **Comments:**
  > **username_0**: Unfortunately this does not work for me. Smarty seems not to be interpreted either, although I have enabled it in civicrm.settings.php with `define( 'CIVICRM_MAIL_SMARTY', 1 );` and clearing cache afterwards. Are you sure this works within the "Subscribe Message"?  
  
  ---
  
  