I have created a content type that has some tokens within the read-only body section so that other custom fields that the user enters when they create content based on this content type are mapped to its associated token within the body section. If the user enters information within a optional field then that entered information replaces the token when the node is saved. The problem is for optional fields when they don't enter a anything within it then the saved node contains the token name instead of an empty section which is what we want.

  • I haven't tried this, but perhaps you can make the DEFAULT value of the optional field a space or something - so it's not empty? Jun 17, 2013 at 14:55

1 Answer 1


I have figured it out with my own custom module:

function mymodule_tokens_alter(&$replacements, $context) { if ($context['type'] == 'node') { $keys = array_keys($context['tokens']); foreach ($keys as $key) { if (isset($context['tokens'][$key]) && !isset($replacements[$context['tokens'][$key]])) { $replacements[$context['tokens'][$key]] = ''; } } } }

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.