Drupal shorthand... tokens, variables, etc????

highvoltage - January 8, 2009 - 23:07

The more I explore drupal the more I am made aware of people using something sometimes referred to as drupal shorthand(I guess), but I never can find a detailed explanation of this. I only stumble on the existence of a specific token or whatever through issues really. Obviously they allow you to insert placeholders into body text or other places, which is a powerful tool, but I really don't know how to make full use of these because explicit information on them is hard to come by as if it's a trade secret or something.

I see various types such as these foudn in the login settings of the site:

!username
!login_uri
!site team

No explaination or list of all possibles for these found anywhere so far.

Then there's Tokens as provided by the module. Some Using '%' others are things like [nid] or [tid]... Haven't managed to find a list of these yet, although the filefield paths module has shown me many. Maybe the above examples using '!' are tokens too? I've also seen some that begin with dollar signs.

Can somebody explain the various types and usages of all this shorthand stuff? Are they all tokens provided by the token module? Do modules have their own tokens defined that don't work unless that module is installed?

There really needs to be a cheatsheet of all these somewhere...

Filefield paths does provide a list of many, though I don't know if any are dependant on that module or not.

Thanks for reading.

I am guessing for the first

nevets - January 8, 2009 - 23:17

I am guessing for the first part you are looking at the t() function. It allows place holders for values in the string and the values are provided in an array key by the placeholder name. See http://api.drupal.org/api/function/t/6 for detail on t().

Do modules have their own

dman - January 8, 2009 - 23:38

Do modules have their own tokens defined that don't work unless that module is installed?

yes.

Different modules occasionally provide different token-like stings in totally different contexts to do different things.
Thus, there is no global list, or assurance that anything will behave out of context. None are provided globally by Drupal core (AFAIK)

pathauto and filefield for example made up a bunch of tokens relevant to its job. Documentation of those should be provided there on the screen.
token.module is attempting to provide an API for this sort of stuff, but it's up the the module in control of your individual textarea whether it will have an expected affect.

Looking at the site settings, I see the instructions

Available variables are: !username, !site, !password, !uri, !uri_brief, !mailto, !date, !login_uri, !edit_uri, !login_url.

Um? The "Trade Secret" you are looking for is the documentation you found. THOSE are the tokens available for use in that textarea. No more, no less. o_O

You will ALSO see tokens used in all drupal code (if you look at the code) as part of the t() translate function.

<?php
t
('this is a %type example of !funcname in action', array('%type=>'made-up', '!funcname'=>'translation abstraction));
?>

You should be able to see from that that the tokens are made-up on-the-fly there. This is solely for internationalization of strings. There is NOT a list of all those - unless you count the .pot files.

See the documentation for t() for an explanation on the difference between % and ! . It makes sense.

.dan.
if you are asking a question you think should be documented, please provide a link to the handbook where you think the answer should be found.
| http://www.coders.co.nz/ |

"Um? The "Trade Secret" you

highvoltage - January 8, 2009 - 23:54

"Um? The "Trade Secret" you are looking for is the documentation you found. THOSE are the tokens available for use in that textarea. No more, no less. o_O"

So what you're saying is... No more magic words?

I...

Nuuuuuuuuu! \._./

Thanks for the information guys. That clears a lot up.

Specific to context

yelvington - January 8, 2009 - 23:39

What you're describing is specific to the contexts in which they are used. Various system emails have embedded tokens that are automatically replaced, et cetera, but the tokens are not global.

Some modules use the token module API to implement this functionality, but again, the replacement activity is specific to the form or other context.

 
 

Drupal is a registered trademark of Dries Buytaert.