There are certain values that are liable to appear in many places on my site (corporate-owned stores, independent stores, # of brands carried, and so forth) that content authors and editors are not likely to keep up-to-date very well on every single page in which they appear.

I can put them in variables in (e.g.) settings.php, and then put PHP snippets in any nodes that need to use them, but that has obvious downsides:

  1. content authors cannot update the values when they change
  2. content authors cannot edit the text that contains the PHP snippets
  3. unless of course I give them permission to do that, but that's probably not a great idea

I'm currently experimenting with using the Token Filter module to allow putting tokens like [node:field_corporate_stores] in content fields in a node. This works just fine if that field is on the node that also has the body content in which it is being replaced. But of course that would defeat the purpose: I want one node that contains the values, and to be able to use an indefinite number of other nodes that will consume the values. But I don't see how to do that.

How do I define data_node for a token like [data_node:field_corporate_stores]??? (Without using any PHP snippets in the node.)

  • 2
    Take a look at Custom Tokens module.
    – kalabro
    Dec 19 '12 at 22:12
  • @kalabro Looks nice, but it's still in beta, and doesn't appear to be getting updated often... have you used it without problems?
    – iconoclast
    Dec 19 '12 at 22:21
  • @kalabro: if you make this an answer I'll accept it (unless there's a better way that someone else comes up with, but that seems unlikely)
    – iconoclast
    Dec 20 '12 at 14:14

This is even more new than Beta, but look at the Sandwich module that looks like most of its configuration is in 1 place (across all nodes of X type for instance).

The module sits at ~400 lines of code and has it looks like 2 small example usage modules/themes.

EDIT: to be clear this goes off custom markup I believe like, MY_CUSTOM_VALUE, in a body field of a node which would regex out to be whatever value you implement in a module. With page caching turned on shouldnt be a huge hit. You keep your "values" in code and dont depend on the Token module.

  • Looks interesting...
    – iconoclast
    Dec 19 '12 at 23:35

I would take a look at the Custom Filter module. I looked at it a year or so ago but decided to roll my own, but from memory, it allows you to specify your own systemwide token substitutions.

  • That module looks extremely useful. For my purposes described in this question, I think Custom Tokens is a better fit, but Custom Filter looks like a perfect solution for some other problems I was puzzling over.
    – iconoclast
    Dec 23 '12 at 4:01

The Custom Tokens module seems to be a nearly perfect solution for this.

In its favor, it provides an administrative interface that is easy for my content editor to use (something that requires dealing with regular expressions would likely confuse her, even if it is a more powerful, more general-purpose tool). Being easy for my content editor to use is very important, as she may identify more and more values over time that are good candidates for replacing tokens, so that they can be centrally managed and kept up-to-date.

On the downside it limits me to a particular syntax for the tokens, such as [custom:my-token-name-here]. It would be nice if I could in the very least use underscores instead of hyphens. It would be even better if I could use something like {{my_token_name_here}}, but that's not a big deal. All in all a good module to have in your bag of tricks.


You can have a admin form which will capture all these values and store it in the variables table. Then you can use Token Var module to use those values as tokens.

Note : Currently it supports only non array values, but it can easily be extended to support the arrays too.

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.