tokens

fago's picture

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

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.

Login to post comments
laken's picture

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

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.

16 comments · Read more
cwarden@groups.drupal.org's picture

tokens in node body

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]') ?>

Login to post comments
greggles's picture

Barcelona Event

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.

2 comments

Confirmation email token issue

Alright, I believe I know how to do some formatting (although I haven't done much yet, but I know it's working), and my custom cc processing module seems to be working. Ouch! My brain is melting. What a way to get my feet wet in the Drupal waters!

Anyway, two (hopefully!) final questions:

3 comments · Read more
Syndicate content