1

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

3
  • One example would be the civicrm_tokens and civicrm_tokenValues functions at github.com/civicrm/org.civicrm.casetokens/blob/master/…
    – Demerit
    Aug 15, 2021 at 16:06
  • You may also want to keep an eye on 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.
    – Demerit
    Aug 15, 2021 at 17:24
  • Thanks - all looks beyond my abilities so I will have to find another way :) Aug 15, 2021 at 19:06

1 Answer 1

1

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}
1
  • That is brilliant, it works perfectly - thank you! Aug 18, 2021 at 20:56

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.