[development] General token parser (API), does it exist?

Steven Wittens steven at acko.net
Wed Dec 6 20:28:11 UTC 2006


> The global ones -- the name of the current user, the name of the  
> site, an so on -- are pretty easy. Do you think it woudl be  
> worthwhile to centralize more complex ones, like 'variations on the  
> creation date of the passed-in node,' and 'the uid of the author of  
> the node', etc?

I think the idea of global tokens is rather weird. Now, tokens are  
always local to a single t() call. If tokens are shared between  
strings, this is only because it is explicitly done by the coder. If  
we start making some tokens globally available, there is absolutely  
no argument against adding more arbitrary tokens to this list. It'll  
explode into a zoo of random variables.

I think we perhaps do need to look at a way of using e.g. PHP code in  
these welcome mail-like strings. That way, you can use arbitrary code  
to retrieve any value you need. You could even make it backwards  
compatible:

$text = strtr(drupal_eval($text), array('%token' => ...));

if no <?php ?> tags are used, it reverts to simple strtr() replacement.

Steven



More information about the development mailing list