I'm looking for some way of having variable defined by admin which can be displayed in some fields or nodes.

Real use case: I have that specific date that changes periodically. And I want it to appear in some places, ie. within text of some node body (with possibility of fixing the variable ie. putting some text instead of date, but it's not a matter of my question).

My guess: create some hook to preg_replace all occurences of some string, ie. ##VAR_VARNAME1## with certain fields of nodes or within field texts. But actually I know that it will occur mainly in 2 or 3 places within my website (which is for sure body of one specific node and text of 1 menu item).

Any ideas to make this efficient and quick?

edit: I believe it's easy to do with defining new block.. but how about way I mentioned above..

1 Answer 1


Try the Custom Tokens extension to the token module. Here is a quote about it (from the module's project page):

... gives the user the ability to create custom tokens for specific replacements that can improve other modules relying on the Drupal 7 token API or, for Drupal 6, the Token module.

Versions 7.x-1.x and previours relied on PHP evaluation to build custom tokens.

The new 7.x-2.x relies on input filters. While still allowing for PHP tokens through the D7 core PHP filter module, administrators can permit only HTML or plain text custom tokens.

  • Not bad! Actually now I see that I can just extend my module and allow to use new tokens this way. Probably more important is now to find way of using tokens within menu items or nodes (token_replace function). Thank you.
    – wtk
    Jul 6, 2012 at 13:35
  • No problem, glad to help! Would this work for tokens in menus? drupal.org/project/menu_token
    – aendra
    Jul 6, 2012 at 14:04
  • I saw that too, but since I'd already overriden default menu items (to more generic markup with text and multiple links) I guess I need to do this by my own. Nevertheless - thanks, enjoy your day :)
    – wtk
    Jul 6, 2012 at 14:12

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.