Drupal - How to use node tokens for displaying field values of content type

Drupal token module

If you have been creating content types, it is obvious that you would not like to display all the fields one after another. But what if you wanted to display a field content in between some text, say the name of the author or say you have a date field etc.

In Drupal you can install a module called Token and Token filters modules which will get you a list of these field modules and many more. You can use them in the following format: site:name (within square brackets)   for current site name of for a field value from current node you could say  node:field_date (within square brackets) which would be a date field in the current content type.

But before you can use the modules you need to enable them as well as you will need to add the token filter to your Text format filter.

  • Go to: Administration » Configuration » Content authoring » Text Formats
  • Here configure the text formats that you want to use the Token filter
    • Enable token filter and place the filter at top - save config.
    • Token Replacement
    • Now you are ready to use these tokens in your nodes.

Let us say if I wanted to display author and title for this page i can simply use token current-page:title in square brackets

If you are using a rich text editor then you will have to place this node by disabling rich-text  and adding the value in appropriate place.

Once done you will be able to show the title like this: Drupal - How to use node tokens for displaying field values of content type

A list of tokens is available at /admin/help/token (you will have to add square brackets [type:token])

  1. Author of node - node:author -> dexter
  2. Content ID - node:nid -> 122
  3. Date created - node:created -> Thu, 12/09/2021 - 08:49

Note on Dates: dates can be formatted in interesting ways by using PHP date format options.

  1. Using the Date created token of the node Let us say you want to display the date type value directly in default formatting:
    1. node:created -> Thu, 12/09/2021 - 08:49
    2. Date in Day-Month-Year format: node:created:custom:d-M-Y
      1. 09-Dec-2021
  2. If you are using a date field with say name of the field is field_date
    1. Then you could use something like the following:
    2. node:field_date-formatted:0:date_default:custom_date_format-M DY
Main category

Add new comment

Filtered HTML

  • Web page addresses and email addresses turn into links automatically.
  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
1 + 0 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.

"Natraj"  Bungalow,
Colony No.7,  Sr.No. 38.
(Lane Behind Sai Baba Mandir)
Kale Borate Nagar, Hadapsar,
Pune - 411028.
Get Directions