Token was an optional Drupal 6 module and proved so popular that it is built into Drupal 7. There is an optional Token add-on module to provide a user interface and some additional tokens not provided by the built in module.
The Drupal 7
Standard install includes Token. Token is not in the
If you are a Drupal module developer, download Token from drupal.org/project/token. Token does not do anything immediately visible, instead it provides a service to your modules and makes one part of module development easier.
You sometimes want to replace text with other information. You might want to replace
[example] with a drawing loaded up as an image. Your code might look for the example token then use the page node number to find the right example illustration. The Token module will find the example token for you, pass the information to your code then replace the token with your text. All you have to do is tell Token what you are looking for and the name of your function to supply the replacement text.
Token arrives with many tokens predefined including the site name and other common information. Many add-on modules add additional tokens.
Updates of the Token add-on module from 7.1 to 7.2 to 7.3 to 7.4 change code and do not require database changes, no update.php changes. Some of the recent changes in add-on modules providing tokens are to standardise conflicting names. Check updates for changes in token names and change your tokens to fit the changes.
There are reasons for not using Token in Drupal 6 and one reason has gone away. When you develop your own Drupal add-on modules, you want to make them dependent only on Drupal core modules where possible. Token is not standard in Drupal 6 and is painful to use for some tasks. At the start of Drupal 6, there was a sensible reason to develop modules with your own substitution. Now that Token is in Drupal 7, you can start using Token in Drupal 6 knowing your upgrade path is safe.
Token does add extra page processing overhead to find the tokens and replace them. Token should be faster than performing separate find and replace processes from several different modules. Token lets you decide how you want to identify tokens and the default identification is compatible with the WYSIWYG editors used with Drupal.
The bulk of Token substitution should occur during page creation and the conversion of content to HTML. The HTML version of the page is cached for anonymous users and should not carry an overhead from Token. Logged in users get a fresh page every time and will see the overhead of Token. Logged in users will see overhead from a lot of modules. The substitution overhead will, in most cases, be less than the overhead of creating the data used for the substitution.
The main point is the overhead will only be significant if one module uses Token for one substitution. When several modules perform substitution, Token should combine the substitutions in the most efficient manner and reduce the total overhead. Once you start using Token for one thing, use it for all substitutions.
Prefix and suffix
Token lets you change the format of tokens. You can use
$example!, anything you like that does not conflict with HTML and other modules.
I had a problem using Token for automated page content substitution. It is easy to set up for substitutions into paths but not into the content body. I ended up using my own code for several modules because Token is missing some bits.
Token provides a replacement function for text and it does nothing special. Token then provides a full service for paths. What it needs is the full service for content bodies and teasers plus an add-on module to control those tokens by content type plus an add on module to control those tokens by role. Drupal 7 now has many add-on modules contributing tokens and several modules adding token use to new parts of Drupal.
Token is in Drupal 7 core and is something worth learning. If Token does almost what you want, but not exactly what you want, look at all the add-on module working with Token.