I am looking for a module or a hook that allow me to use if conditions with tokens.

For example I want to check if a field is equal to a specific value or text


any ideas will be helpful.

  • You has tried with hook_token ? – vinhdv Aug 30 '18 at 5:48
  • @vinhdv its been a long time since I posted this question. I didn't try hook_token for this issue. I remember I wrote a module to solve my issue at the time. – Aboodred1 Aug 30 '18 at 17:08

Here is an idea, which I have not tried yet.

Sometimes you have tokens in combination with text formats. E.g. in commerce_checkout_completion_message_pane_checkout_form() the token replacement happens first, before the text format is applied. I am not sure if I agree with this order, but in this case it gives us some interesting options.

You could define a custom text filter which detects and evaluates markup like this:

{if true}hello{else}goodbye{endif}

and then you can use tokens to insert the true/false.

{if [token-which-returns-true-or-false]}hello{else}goodbye{endif}

This still leaves a lot in the open. Most tokens do not produce true/false, so maybe instead you want real equation formulas. But it is a direction you can explore further.

| improve this answer | |

You can try to build it with Rules, but I'm not sure.

Another way is to make you own token module to get it. Token api is one of the easiest api from drupal.

| improve this answer | |
  • I am actually looking for something more handy for future projects. Something like token_logic module – Aboodred1 Sep 14 '12 at 20:26
  • What is token_logic module?? – donquixote Feb 1 '18 at 19:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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