GVS is now part of Acquia. Acquia logo

Token Module: How I Learned To Use the Token API and Stop Re-Implementing Dynamic String Replacement

Greg's picture

Greg Knaddison

Growing Venture Solutions

July 2008

DrupalCamp Colorado

What are Tokens?
Little bits of text that get replaced with other bits of text.

Have you used:
ecommerce like ec_mail Custom Breadcrumbs Organic Groups - og Automatic Nodetitles (aka auto_nodetitle) Pathauto Upload Path PressFlow Placement Ubercart Invite Tokenize Audio Workflow-ng CCK Taxonomy CCK Full Name CCK Taxonomy SSU (Super Select Ultra) Fieldset Menus Node Relativity Backup and Migrate User stats Simplefeed Page title Token Node Tokens (TNT) Temporary Invitation Activity Type-local nids FileField Actions Token Email for 5.x
Me too.

If you haven't...here's a quick demo.

Token for Developers:
// Consuming tokens
// [user-name] - The name of the currently logged in user.
$original = 'Hello [user-name]';
drupal_set_message(token_replace($original, $type = 'global', $object = NULL,
$leading = '[', $trailing = ']')
// Prints "Hello greggles"

Providing Your Own Tokens
hook_token_list()
hook_token_values()

Questions? Ideas For Improvement? Bugs?

GVS projects

CertifiedToRock.com was created to allow community members and employers to get a sense of someone's involvement with the Drupal project.

GVS is now part of Acquia.

Acquia logo

Contact Acquia if you are interested in a Drupal Support or help with any products GVS offered such as the Conference Organizing Distribution (COD).

We Wrote the Book On Drupal Security:

Cracking Drupal Book Cover