| Drupal

How to Use Tokens in Drupal Fields

How to Use Tokens in Drupal FieldsToken is one of the 3 most popular modules in Drupal.

It allows you to use small placeholders to automatically complete tasks.

To take a simple example, if you put [site:name] on your site, it will be replaced by the actual name of your site. To take a more complicated example, you can use Token together with the Pathauto module to automatically create URL patterns for your whole site.

However, Token needs other modules to work. If you want to use Token inside fields, there are several options but one of the most reliable is a module called Token Filter.

Enable Drupal's token filter module

If you have Token and Token Filter enabled, here's how to add tokens to your fields:

  • Go to Configuration > Text formats
  • Click "Configure" next to the text format you want to use. Be careful with this - do not choose a text format that your regular site visitors will be able to use.
  • Check the "Replace tokens" box, as in the image below.
  • Click "Save Configuration".
  • Go to Structure > Content types > Manage fields
  • Click "Edit" next to a field
  • There will be a "Browse available tokens" option.
Browser available tokens in Drupal
  • You can use these tokens to set up default values for your fields:
Default values for tokens in Drupal fields

It's worth noting that some fields types use the "Plain text" format, by default. So, make sure you have token support available for Plain text if needed.

However, be careful with this. Remember that you don't want to give token access to anyone on your site. In the wrong hands, tokens could expose private information.

Text processing for Drupal tokens

About the author

Steve is the founder of OSTraining. Originally from the UK, he now lives in Sarasota in the USA. Steve's work straddles the line between teaching and web development.