Answers.Body: <p>If the hooks aren't the direction you want to go, you can do this in your mail template, just you'll need to update it if the labels change or you add new values, and doesn't work well if you need more than english:</p>
  <pre><code>{capture assign=myvar}{contact.custom_1}{/capture}
  {if $myvar == '1 - 10 people'}1
  {elseif $myvar == '11 - 20 people'}2
  ...etc...
  {/if}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-08-18T20:56:58.790Z
Answers.Text: That is brilliant, it works perfectly - thank you!
Answers.UserDisplayName: Robin Fenwick
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-08-15T19:18:37.990Z
Answers.LastActivityDate: 2021-08-15T19:18:37.990Z
Answers.UserDisplayName: Demerit
Body: <p>Going round in circles on something and wonder if anyone can help. Civi 5.40.1 on Wordpress.</p>
  <p>We have a profile which allows the user to enter data about themselves into custom fields.  E.g., from a drop down list then can choose how many people work in their organisation, or what their organisation's annual turnover is.</p>
  <p>So for example, the data for &quot;how many people work in your organisation?&quot; may look like:</p>
  <pre><code>Label              Value
  1 - 10 people      1
  11 - 20 people     2
  21 - 50 people     3
  </code></pre>
  <p>When sending a mailing in CiviMail, I want to merge in some of the <strong>values</strong> using tokens. But when you do this, CiviCRM injects the label, not the value.</p>
  <p>I found this reference to &quot;token hooks&quot; which looks like the nearest thing to what I need? <a href="https://civicrm.org/blog/lobo/new-in-22-token-hooks-and-smarty-templates-for-civimail" rel="nofollow noreferrer">https://civicrm.org/blog/lobo/new-in-22-token-hooks-and-smarty-templates-for-civimail</a></p>
  <p>I wondered if anyone can provide a real life example of how this works, or provide more context on how hooks work.  I am much better at editing existing or sample code than I am at creating new code from scratch!</p>
  <p>Thank you!</p>
  <p>Robin</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-08-15T16:06:01.747Z
Comments.Text: One example would be the civicrm_tokens and civicrm_tokenValues functions at https://github.com/civicrm/org.civicrm.casetokens/blob/master/casetokens.php#L208
Comments.UserDisplayName: Demerit
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-08-15T17:24:57.603Z
Comments.Text: You may also want to keep an eye on https://lab.civicrm.org/dev/core/-/issues/2650 and related. It suggests that coming in a future version you'll be able to do `{contribution.contribution_status_id}` to get the value, and `{contribution.contribution_status_id:label}` to get the label. Although it does say custom fields are not in the plan for now.
Comments.UserDisplayName: Demerit
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-08-15T19:06:37.240Z
Comments.Text: Thanks - all looks beyond my abilities so I will have to find another way :)
Comments.UserDisplayName: Robin Fenwick
Tags: <civimail><tokens>
Title: Tokens - Need Values, not Labels
ThreadText: # Tokens - Need Values, not Labels
  
  (Asked by: username_0 on 2021-08-15)
  
  Going round in circles on something and wonder if anyone can help. Civi 5.40.1 on Wordpress.
  We have a profile which allows the user to enter data about themselves into custom fields.  E.g., from a drop down list then can choose how many people work in their organisation, or what their organisation's annual turnover is.
  So for example, the data for "how many people work in your organisation?" may look like:
  Label              Value
  1 - 10 people      1
  11 - 20 people     2
  21 - 50 people     3
  
  When sending a mailing in CiviMail, I want to merge in some of the values using tokens. But when you do this, CiviCRM injects the label, not the value.
  I found this reference to "token hooks" which looks like the nearest thing to what I need? https://civicrm.org/blog/lobo/new-in-22-token-hooks-and-smarty-templates-for-civimail
  I wondered if anyone can provide a real life example of how this works, or provide more context on how hooks work.  I am much better at editing existing or sample code than I am at creating new code from scratch!
  Thank you!
  Robin
  
  **Tags:** civimail, tokens
  
  > **Comments:**
  > **username_1**: One example would be the civicrm_tokens and civicrm_tokenValues functions at https://github.com/civicrm/org.civicrm.casetokens/blob/master/casetokens.php#L208  
  > **username_1**: You may also want to keep an eye on https://lab.civicrm.org/dev/core/-/issues/2650 and related. It suggests that coming in a future version you'll be able to do `{contribution.contribution_status_id}` to get the value, and `{contribution.contribution_status_id:label}` to get the label. Although it does say custom fields are not in the plan for now.  
  > **username_0**: Thanks - all looks beyond my abilities so I will have to find another way :)  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-08-15. Score: 1 | Accepted answer
  
  If the hooks aren't the direction you want to go, you can do this in your mail template, just you'll need to update it if the labels change or you add new values, and doesn't work well if you need more than english:
  {capture assign=myvar}{contact.custom_1}{/capture}
  {if $myvar == '1 - 10 people'}1
  {elseif $myvar == '11 - 20 people'}2
  ...etc...
  {/if}
  
  > **Comments:**
  > **username_0**: That is brilliant, it works perfectly - thank you!  
  
  ---
  
  