Tokens

The Token module for Drupal 4.7 and 5 exposes simple text substitution tokens like [title] and [user-name], for use in path generation, mass mailings, and many other situation where admins want to set up text replacement patterns without using PHP snippets. Other modules can expose their own domain-specific replacement tokens (like information about a purchase, or an organic group that a user is a member of) and use Token's centralized replace() function to replace token occurrences in any piece of text.

If you are curious how you might use tokens or who is using it, consider this list of modules that use token

If you want to help get Token into Core then there's the issue. Please don't just subscribe to the issue or you will lose karma points in the eyes of some of Drupal's most respected community members.

Tokens and Domain

private
group: Tokens
davidnaian@drup... - Thu, 2009-05-14 23:31

Hi, I am intensively testing Domain.module and have noticed that in the Modules that Use Token Module the Domain Access module is not listed. It would be interesting to know if there are some issues about or any kind of feedback you may know about, that may be related to the 2 modules installed togheter. Feedback very much appreciate.

new releases of token

greggles's picture
private
group: Tokens
greggles - Thu, 2009-05-07 11:59

It's about time for a new release, right?

If you are on of the people interested in this, please head on over to issues to fix before a 6.x-1.12 Release to help finalize the 2 remaining patches and suggest any issues that you'd like to see fixed prior to the release.


user_pass_reset_url token

public
groups: Rules · Tokens
shushu - Sun, 2009-03-22 10:25

I am trying to use the CCK+Rules+Token module to accomplish creation of a user when a content with its email address is being created.
This user should get an email notification with his password and/or a user_pass_reset_url link.

The token_user.inc does not provide password, nor the creation of the user using the rules action.
In addition, the !password of the user_mail_tokens does not apply here.

Any suggestion what should be the right way to solve this ?

Regards,
Shushu

Tokens & RDF in d7 - can they benefit from each other?

fago@drupal.org's picture
public
groups: Semantic Web · Tokens
fago@drupal.org - Sat, 2009-03-07 15:58

Right now there is a issue for getting token into core and one for getting some RDF into it. I wonder if makes sense to base the token patch upon the RDF stuff. So once we have some semantics attached to our objects, we can use them as a starting point for doing the token replacements.

The other way round, the RDF patch could learn from the tokens code - as the actual problem to solve is quite similar. The way the patch in #74 uses simple handlers to get tokens would make sense for RDF too. Then the token implementation can go and build upon that and reuse the handlers returning RDF string literals. Similarly, the approach described in #77 for doing actual token replacements could also be used for getting chunks of RDF for a bunch of objects.

Then apart from avoiding inventing the wheel twice, we could easily make both APIs consistent, so they can be used the same way.


Better token lists

sirkitree's picture
public
groups: Tokens · Usability
sirkitree - Thu, 2009-02-26 01:28

Has anyone come up with a better way of presenting the list of tokens to users? I'm finding that what I'm doing is really ugly and would love to know if anyone has seen any good examples of how to present tokens in a more usable manner.
Configure an advanced action | Community


Possible New Drupal Modules

public
ausvalue@drupal.org - Mon, 2009-01-12 03:28

Possible New Drupal Modules

I have a few ideas for Drupal modules. All are related to Social Networking Sites in that they are an attempt to allow nodes to appear as if they are part of each users account. The first and third modules are related to the Token module.

I'm anticipating developing these modules for Drupal 6 and later versions of Drupal. Not for Drupal 5. I've done some work towards the first module (Type user nids) but very little for the other two.

I'm asking the following:

1) Are these likely to be useful to the Drupal community?

Using tokens in a menu link

flickerfly's picture
public
group: Tokens
flickerfly - Sat, 2008-10-18 15:29

I have a menu item that I'd like to make different for each user. It's an internal page that accepts &_GET in the URL.

I'm thinking I could skip the user past entering this information in manually by providing the url like http://site.com/?user=loggedinuser&target=somepage. Could I fill this username with the drupal username using a token or are they just not available in the context of menu entries?

How else could I solve this if not with tokens?


New releases of Token module - Suggest issues and help test

public
group: Tokens

Hi folks,

I think it's about time to do another relase of both the 6.x and 5.x branches of code. The last issue I'd like to fix is menu* generally broken which has a patch that needs review.

Anything else that should really really be fixed? Add it here:

And if you're using the latest 5/6.x-1.x-dev version of token and it's working for you it would be nice to hear that as well.

Token for the email address of the author of the comment that someone replied to

public
group: Tokens
nikita - Wed, 2008-07-02 08:36

Is there a token (or a way to create one) that can be used to notify the author of the comment (not of the node) that someone has replied to it?

Does module exist to let site editors maintain own tokens and replacement text?

laken's picture
public
group: Tokens
laken - Thu, 2008-06-19 19:30

I really love token module! I'm especially loving it in pathauto and auto nodetitles - very powerful.

Is there a module to permit site editors to create and maintain their own tokens and corresponding replacement text, either through a UI or in a text file?

The site I'm building needs to let editors store snippets of text which can be reused in many places. For instance we might have this in node content: "McDonalds has sold [num_bugers_sold] in their history". We'd need a way to edit the value for [num_bugers_sold] and have that token update wherever it's used.


tokens in node body

cwarden's picture
public
group: Tokens
cwarden - Thu, 2008-05-29 23:27

What's the proper way to replace tokens within a node body?
I've created a simple module that implements hook_token_values and
hook_token_list, but to use my token within a node body, I've had to
implement hook_nodeapi, which doesn't seem right.

<?php
function mymodule_nodeapi(&$node, $op, $a3 = null, $a4 = null) {
   if (
$op == 'alter') {
     
$node->body = token_replace($node->body);
   }
}
?>

How about within a template? Is this discouraged?

<?= token_replace('[my-token]') ?>


Token replacement from specific vocabularies?

laken's picture
public
group: Tokens
laken - Tue, 2008-05-27 22:36

I've got a content type with a Name field, and 2 taxonomy vocabularies applied, one for "person type" and one for "issue type". I'm using auto node titles module, and I want to to format the titles like this

[name], [person type], on [issue type]

e.g.

Andy Laken, Volunteer, on Governance

But in the replacement pattern list, I find only [term] which is the "Name of top taxonomy term" (not sure what that means.) My question - is there any way to get a replacement pattern to grab the name of the term for a specific vocabularies, when more than one vocab applies to a node?


Token and CCK nodereference

Hugo Wetterberg's picture
public
group: Tokens
Hugo Wetterberg - Tue, 2008-04-29 07:02

Hi All,
Thanks for a great module. I'm trying to make pathauto construct hierarchical urls using cck-nodereference fields for the hierarchical relationships. And I have some questions about the tokens that are created for nodereference fields. As far as I can see the only usable token is [fieldname]-nid. Is this correct, or are the *-title and *-link tokens populated in certain circumstances?


Replacement Patterns Not Available

public
group: Tokens
gregrenner - Wed, 2008-04-16 15:49

Greetings,
I'm new to this group and to the Token module, so forgive my ignorance with this question. Its possible I missed something basic. I am unable to see and replacement patterns anywhere on my site where they should be listed. For example the Auto Nodetitles module provides a fieldset which is supposed to list the available replacement patterns, but there isn't anything in the fieldset (attachment1). Its also not replacing my [field_event-raw] with anything. I have the same issue in the Workflow-ng pages, nothing shows up (attachment2), but my tokens ARE being replaced.

Replacement Patterns Not Available

public
group: Tokens
gregrenner - Wed, 2008-04-16 15:49

Greetings,
I'm new to this group and to the Token module, so forgive my ignorance with this question. Its possible I missed something basic. I am unable to see and replacement patterns anywhere on my site where they should be listed. For example the Auto Nodetitles module provides a fieldset which is supposed to list the available replacement patterns, but there isn't anything in the fieldset (attachment1). Its also not replacing my [field_event-raw] with anything. I have the same issue in the Workflow-ng pages, nothing shows up (attachment2), but my tokens ARE being replaced.

5.x-1.11 Pre-release Bug Tracking Wiki

public
group: Tokens

Howdy folks,

I think (and karen thinks) that we've hit the time for a 5.x-1.11 release. Are there any major bugs we should fix prior to that release? Can anyone else confirm that the 5.x-1.x-dev release is working well for them (I use it on all my sites, but I don't exercise all of its features...) Post links to the issues in this wiki or as comments on this page. If you think it's ready to go, posting a message saying that would help as well! Thanks!

5.x-1.11 Pre-release Bug Tracking Wiki

public
group: Tokens

Howdy folks,

I think (and karen thinks) that we've hit the time for a 5.x-1.11 release. Are there any major bugs we should fix prior to that release? Can anyone else confirm that the 5.x-1.x-dev release is working well for them (I use it on all my sites, but I don't exercise all of its features...) Post links to the issues in this wiki or as comments on this page. If you think it's ready to go, posting a message saying that would help as well! Thanks!

format_date? which timezone to use?

greggles's picture
public
group: Tokens
greggles - Sat, 2008-01-05 10:37

There's an issue with some of the dates in tokens that they don't get set to the right values.

Of course, the question is what's the "right" value?

I'm writing here to ask if you'd rather get the server time or the default site time or the user's timezone.

The first person who asks for "configurable by the token admin" will get stabbed with a "work on token2.x where attributes are possible"-spoon. (yes, a spoon, it will hurt more).


format_date? which timezone to use?

greggles's picture
public
group: Tokens
greggles - Sat, 2008-01-05 10:37

There's an issue with some of the dates in tokens that they don't get set to the right values.

Of course, the question is what's the "right" value?

I'm writing here to ask if you'd rather get the server time or the default site time or the user's timezone.

The first person who asks for "configurable by the token admin" will get stabbed with a "work on token2.x where attributes are possible"-spoon. (yes, a spoon, it will hurt more).


Arbitary tokens

jredding's picture
public
group: Tokens
jredding - Sat, 2007-12-01 18:39

In the last two days I whipped up a very quick module that allows you to create arbitrary tokens (i.e. /node/add/token) for use with the token modules. This was primarily created for use with the tokenize module so that through the UI a user could create tokens and select which fields could use those tokens.


Arbitary tokens

jredding's picture
public
group: Tokens
jredding - Sat, 2007-12-01 18:39

In the last two days I whipped up a very quick module that allows you to create arbitrary tokens (i.e. /node/add/token) for use with the token modules. This was primarily created for use with the tokenize module so that through the UI a user could create tokens and select which fields could use those tokens.


Token and the Rep[lacement]Tags module

profix898's picture
public
group: Tokens
profix898 - Wed, 2007-11-21 11:50

I'm author and maintainer of the Rep[lacement]Tags module (http://drupal.org/project/reptag). As mentioned and explained before the reptag module is a regexp-based, node-centric, bigger brother/sister of the Token module. The idea behind both modules is quite similar and even the API is similar on some points. For Drupal 6 I'd really love to see the modules complement each other (or even merge). To achieve that (at least for most of the features) only a few changes to Token and some more to Reptag ;) would be required.


Token and the Rep[lacement]Tags module

profix898's picture
public
group: Tokens
profix898 - Wed, 2007-11-21 11:50

I'm author and maintainer of the Rep[lacement]Tags module (http://drupal.org/project/reptag). As mentioned and explained before the reptag module is a regexp-based, node-centric, bigger brother/sister of the Token module. The idea behind both modules is quite similar and even the API is similar on some points. For Drupal 6 I'd really love to see the modules complement each other (or even merge). To achieve that (at least for most of the features) only a few changes to Token and some more to Reptag ;) would be required.


Modules that Use Token Module

public
group: Tokens

Here is a list of some of the modules that use token. If you know of another, please add it.

Some of these modules provide tokens, some just use the token_replace mechanism. But if you are looking for something that will integrate nicely with (for example) Auto Node Title, Page Title, or Pathauto (the consumers of tokens) then you should consider these modules which will probably expose their inner data as tokens to other modules.

Another token enhancement proposal

public
group: Tokens
cwgordon7@drupal.org - Sun, 2007-10-21 01:13

Token should probably provide an easy way for modules to create tokens based on already existing tokens. Let me explain what I mean. For a node, I should be able to pass in 'author-' as a prefix, 'user' as the type, and the node's author as the object. Token would then get all the values for 'user' with the object $user, and would return them as the tokens [author-usertokenpropertyhere].

Another token enhancement proposal

public
group: Tokens
cwgordon7@drupal.org - Sun, 2007-10-21 01:13

Token should probably provide an easy way for modules to create tokens based on already existing tokens. Let me explain what I mean. For a node, I should be able to pass in 'author-' as a prefix, 'user' as the type, and the node's author as the object. Token would then get all the values for 'user' with the object $user, and would return them as the tokens [author-usertokenpropertyhere].

Token enhancement proposal

fago@drupal.org's picture
public
group: Tokens
fago@drupal.org - Tue, 2007-08-21 08:48

Token is great, however there are still some problems that need to be solved. Here is a proposal, which tries to do so.

Problems I noticed are:

  • missing handling of multiple values
  • no way to get tokens of a certain node type and no more
  • no way to get token help for only raw values or formatted ones - which might lead to XSS created by unexperienced users
  • performance: getting all token values for a node takes about 10ms!

I ran over the performance issue while developing workflow-ng. I think 10ms just for replacing a token is far less than ideal. I noticed that user tokens are working quite fast, so I assume that getting and caching all token values takes that long. So I propose to do the replacing in two steps, first off it is determined for each token, if it has been used.Then on the second step, the value for each used token is determined and replaced.
So token needs to get only the values for really use tokens - this should work fast!

Unfortunately, this and the improved formatter handling requires API changes. So consider this as a proposal for token 2.x.


Token enhancement proposal

fago@drupal.org's picture
public
group: Tokens
fago@drupal.org - Tue, 2007-08-21 08:48

Token is great, however there are still some problems that need to be solved. Here is a proposal, which tries to do so.

Problems I noticed are:

  • missing handling of multiple values
  • no way to get tokens of a certain node type and no more
  • no way to get token help for only raw values or formatted ones - which might lead to XSS created by unexperienced users
  • performance: getting all token values for a node takes about 10ms!

I ran over the performance issue while developing workflow-ng. I think 10ms just for replacing a token is far less than ideal. I noticed that user tokens are working quite fast, so I assume that getting and caching all token values takes that long. So I propose to do the replacing in two steps, first off it is determined for each token, if it has been used.Then on the second step, the value for each used token is determined and replaced.
So token needs to get only the values for really use tokens - this should work fast!

Unfortunately, this and the improved formatter handling requires API changes. So consider this as a proposal for token 2.x.


Barcelona Event

greggles's picture
public
group: Tokens
greggles - Sat, 2007-08-04 14:54

Following Dries' request for more presentations I decided that Token module would be a good topic:

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

So, if you are headed to Barcelona and want to learn more about using Tokens, this would be a great session to attend. Similarly, we plan to use some of the time to talk about the "future of tokens" which should hopefully be a useful topic.


Barcelona Event

greggles's picture
public
group: Tokens
greggles - Sat, 2007-08-04 14:54

Following Dries' request for more presentations I decided that Token module would be a good topic:

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

So, if you are headed to Barcelona and want to learn more about using Tokens, this would be a great session to attend. Similarly, we plan to use some of the time to talk about the "future of tokens" which should hopefully be a useful topic.


The future of tokens?

eaton's picture
public
group: Tokens
eaton - Fri, 2007-04-27 04:39

Wow. Pathauto finally made the move!

Token module was conceived when I was writing custom_breadcrumbs and custom_links, and wanted to generate the kind of simple [foo] and [bar] links that had been popularized by Pathauto. I was this close to listing pathauto as a dependency for both modules when I ran into greggles in #drupal and started chatting with him about the need for a centralized 'Just The Tokens' utility that many modules could benefit from.

With the current release of Token module, and the current release of Pathauto, quite a few modules can now plug into "the system."


The future of tokens?

eaton's picture
public
group: Tokens
eaton - Fri, 2007-04-27 04:39

Wow. Pathauto finally made the move!

Token module was conceived when I was writing custom_breadcrumbs and custom_links, and wanted to generate the kind of simple [foo] and [bar] links that had been popularized by Pathauto. I was this close to listing pathauto as a dependency for both modules when I ran into greggles in #drupal and started chatting with him about the need for a centralized 'Just The Tokens' utility that many modules could benefit from.

With the current release of Token module, and the current release of Pathauto, quite a few modules can now plug into "the system."


Syndicate content