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.
- 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])
- Author of node - node:author -> dexter
- Content ID - node:nid -> 122
- 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.
- Using the Date created token of the node Let us say you want to display the date type value directly in default formatting:
- node:created -> Thu, 12/09/2021 - 08:49
- Date in Day-Month-Year format: node:created:custom:d-M-Y
- 09-Dec-2021
- If you are using a date field with say name of the field is field_date
- Then you could use something like the following:
- node:field_date-formatted:0:date_default:custom_date_format-M DY
Add new comment