Could there be a token implemented that would output the body of the node? I'm looking to use it in the "send to an arbitrary mail address" action when a node is created.

#52 body_tokens-181546-52.patch1.62 KBDeciphered
PASSED: [[SimpleTest]]: [MySQL] 200 pass(es). View
#51 body_tokens-181546-51.patch1.62 KBDeciphered
PASSED: [[SimpleTest]]: [MySQL] 200 pass(es). View
#30 node_body_tokens.tar_.gz808 bytesDavid Stosik
#26 token-body_6.x.zip1.32 KBamariotti
#14 body_token.zip1.79 KBtizzo
#10 token.module-token_node.inc_.patch2.03 KBdruvision
FAILED: [[SimpleTest]]: [MySQL] Invalid patch format in token.module-token_node.inc_.patch. View
Members fund testing for the Drupal project. Drupal Association Learn more


fago’s picture

Project: Workflow-ng » Token
Version: 5.x-1.0 » 5.x-1.x-dev
greggles’s picture

Status: Active » Postponed

This could be a performance problem with complex nodes. Marking postponed until we figure out token generation performance.

lordgilman’s picture

Maybe you could use/take a look at the code from the Notify module?
I think the bit under "Helper function to send the notification email." (search for it) is the code that gets the node's body but I could be wrong.

I was looking into using this node as a solution for what I want Drupal to do with newsletters but token + workflow_ng is a much more elegant way of doing things.

greggles’s picture

Well, you can make a "node body" token in a module that you use and just make sure that it doesn't get executed all the time by putting it into a specific namespace. Take a look at the way that paypalnode does it:

That only gets executed when token_replace is called with "PayPal Node" as the $type which effectively limits the frequency of that code actually firing to the times it is needed. You can do the same thing to avoid this performance problem.

lordgilman’s picture

greggles: could this get moved back to the workflow_ng module then? I was sorta asking for a patch for that module anyway.

greggles’s picture

That's not my module - I can't say. I suggest you submit an issue in its queue.

amitaibu’s picture

As a workaround, you can create a field in CCK, called Body and use the token of that field.

fago’s picture

just for reference, the workflow-ng issue:

archetwist’s picture

I've "hacked" the file and added the following to the node_token_values function:

      $values['teaser']           = check_plain(preg_replace(array('/\<\/p\>/','/\n/'),' ',$node->teaser));
      $values['body']             = check_plain(preg_replace(array('/\<\/p\>/','/\n/'),' ',$node->body));
      $values['body-200']         = substr(check_plain(preg_replace(array('/\<\/p\>/','/\n/'),' ',$node->body)),0,200);
      $values['body-400']         = substr(check_plain(preg_replace(array('/\<\/p\>/','/\n/'),' ',$node->body)),0,400);

and, later in the file, under node_token_list:

    $tokens['node']['teaser']         = t('Node teaser');
    $tokens['node']['body']           = t('Node body');
    $tokens['node']['body-200']       = t('First 200 characters of a body');
    $tokens['node']['body-400']       = t('First 400 characters of a body');

I am using the teaser and body-400 tokens and do not observe any performance problems. I need these tokens to allow my users to submit the stories they read to digg-like services.

druvision’s picture

2.03 KB
FAILED: [[SimpleTest]]: [MySQL] Invalid patch format in token.module-token_node.inc_.patch. View

Here is a patch for version 5.x-1.9.5 with archetwist's solution (added body-100 and body-50 tokens).

Professional: Drupal Israel | Drupal Development & Consulting | Eco-Healing | Effective Hosting Strategies | בניית אתרים
Personal: Hitech Dolphin: Regain Simple Joy :)

tizzo’s picture

Status: Postponed » Needs review

I have the same use case described above (workflow_ng send email to users of a certain role) and also need this capability. Is enough known about the performance of token module to reevaluate this?

Are all values populated each time token is invoked? Is what leads to the potential performance problems?

greggles’s picture

Status: Needs review » Postponed

Are all values populated each time token is invoked? Is what leads to the potential performance problems?


Is enough known about the performance of token module to reevaluate this?

I don't believe so.

grendzy’s picture

subscribing. I'd like to use notifications module to email $node->body.


tizzo’s picture

1.79 KB

I was looking to do something similar to what grendzy mentioned using workflow_ng to send the body. After looking at the code of token I can see why performance could be a serious issue. That said, the site that I was building has a reasonably small audience and a very small set of people that act as logged in users (most pages are served from the cache) so I decided it wasn't much of a problem.

What I did was take the patch above and drop it into a little body_token module on my site. Token is pluggable so this is easy to add as long as you're aware of the performance risks. I'll attach the D5 version that I made but USE WITH CAUTION!

mitchell’s picture

Version: 5.x-1.x-dev » 6.x-1.x-dev
Status: Postponed » Needs work

@tizzo: Can you please post this as a patch, possibly for D6?

mitchell’s picture

Status: Needs work » Postponed

nevermind #15.
#7 is the best short-term solution, and as greggles noted in #2, this would require other performance related improvements to token.

jvieille’s picture

We really need to be able to post Nodes body.
I don't really catch the performance issue, a warning in the documentation would address this concern.

I changed my Token module in D6 as in #7, this is what is needed (just be aware of the plain text transformation effect)

A CCK field is not a solution as it would mean to modify existing node types and messing things between past published nodes and new ones.

This is a old issue...

jvieille’s picture

Some improvement needed for the patch:

If the body contents does not render non-alphanumeric characters.

For example, the following text
"Présentation - Ergonomie"

is received like this:
"<h1>Pr&eacute;sentation - Ergonomie</"

I replaced
substr(check_plain(preg_replace(array('/\<\/p\>/','/\n/'),' ',$node->body)),0,50);
substr(preg_replace(array('/\<\/p\>/','/\n/'),' ',$node->body),0,50);

but it does not help much:

Présentation - Ergonomie


marcushenningsen’s picture

I'm using the workaround in #9 and it's working very well. Is there any reason this shouldn't be implemented, at least the shortened versions, or might they also generate perfomance issues?

greggles’s picture

Status: Postponed » Needs work

The reason we aren't doing this is performance.

I don't really catch the performance issue, a warning in the documentation would address this concern.

A warning in the documentation that says "this module, the 3rd most popular one in Drupal, will slow down your site unnecessarily." That just isn't acceptable.

Now, I'm re-opening this because someone could provide a patch for the tokenSTARTERKIT. I'd commit that.

jvieille’s picture

Is performance affected even if the new body tokens are not used?
For example, the "raw user input tokens" have a warning in the code itself, so the user knows when selecting them about possible drawbacks

grendzy’s picture

Yes, it seems hook_token_values() computes values for all possible tokens, without regard to whether they are actually used or not. I don't think that can be changed without changing the API.

grendzy’s picture

Here is something interesting:

adding $values['content'] = node_view($node, FALSE, TRUE); to node_token_values() actually made it faster by a tiny, but seemingly repeatable amount.

As a baseline, 10,000 calls to token replace took 7.098 seconds. After adding the above token, it took 6.976 seconds.

This is with a core page node. I haven't benchmarked it with CCK fields yet, but perhaps the performance worries around this issue are overstated.

yan’s picture

The reason we aren't doing this is performance.

But using %body in a "normal" mail doesn't? I really need to send the node's body AND some fields I only get through tokens.

amariotti’s picture


I'd love this feature as well. I think that if there were some sort of a warning message in the Token Replacement list. Maybe even put it in it's own category with a warning at the top too. I just think that if anyone's going to use it then it will be a unique situation. If they know that it is a resource hog then they will think twice. It could also be an extra token module that would have to be enabled..... either way the option needs to be there for people like us.

EDIT: just realized that at least one other person mentioned the same thing at the bottom of this post. Sorry. :)

amariotti’s picture

1.32 KB

I've gone and just created a new module called token_body that will accomplish this for me. Attached is the 6.x version for anyone that wants to use it. Again, be warned that this is not ideal for many situations due to the server overload. Please use with caution.

mennonot’s picture


Thanks for this module in #36. It seems to be the only hope for sending out an html body using mime mail actions.

I've installed it and I am trying to use it with Rules and Mime mail. It shows up in the token list and I am able to insert it into the body of the message, but its missing in the resulting emails (the other tokens show up). Any suggestions on how to troubleshoot it?

jvieille’s picture

Strange enough that feature does not appear to be a huge issue.
How do Drupalers send newsletters or significant emails to subscribers without the ability to process the nodes' Body?

For the time being, I tweak the module by adding the corresponding lines (#9, #10). I would plan to test this module as well, but there seem to be a very low interest in this...

kenorb’s picture

David Stosik’s picture

808 bytes

I also wrote my own module to provide $node->body and $node->teaser tokens, in four different formats :
- HTML checked (like comment-body is, with check_markup())
- raw
- HTML escaped (with check_plain())
- HTML stripped (with PHP's strip_tags())

Module for 6.x is attached. Will accept suggestions, and maybe create it as a new project here.


jvieille’s picture

#26 does not work: tokens are created and appear in lists, but return only their name

anawillem’s picture

This is not working for me. I see it on the list, but when I create a page, for example, it does not send the node body. It doesn't sent the token text either ([node:body]), and it seems to occupy space in a line up of different tokens so it seems to be processing something....?

I desperately need this to work. I am on 6.19, using this module you have here, and the most current version of the token module (6.x-1.14).

I have tried it on two different sites (one with 6.17).

anawillem’s picture

this being #14 patch... :)

j0nathan’s picture


soulfroys’s picture

I need this too... for messaging ( templates.

roderik’s picture

@soulfroys: install notifications (which is by the same author as messaging), and enable notifications_content module. It has body tokens.

(I don't know why he decided to put the token generation in notifications_content instead of messaging... that situation will probably be rectified sometime...)

soulfroys’s picture

Oh! My bad... Thanks @roderik!

Andrew Gorokhovets’s picture


yeti22’s picture


jasom’s picture

#30 was working for me. Thank you. Now, I need solve how to add comment body.

amariotti’s picture

My fault for not checking back here. After that post I changed jobs and got really busy so haven't come across it until now. Sounds like #30 is a good alternative. Hopefully this can become it's own project.

yub_yub’s picture

Subscribing’s picture


juahoo’s picture


nikkubhai’s picture


Maedi’s picture

+1 #30!’s picture

#30 = joy ;)

Maedi’s picture

Be great if #30 could me merged into the module or made a separate project.

David Stosik’s picture

Deciphered’s picture

Status: Needs work » Needs review
1.62 KB
PASSED: [[SimpleTest]]: [MySQL] 200 pass(es). View

Patch attached adds the following tokens:

Memory consumption results (provided by Devel module) as follows:
Before patch: Memory used at: devel_init()=1.97 MB, devel_shutdown()=11.82 M
After patch: Memory used at: devel_init()=1.97 MB, devel_shutdown()=11.84 M

I don't know if this is enough information or if an increase of 0.02M memory consumption is an issue, but I do believe that this is something that belongs in Token not in TokenSTARTER, and definitely not in a sandbox module.


Deciphered’s picture

1.62 KB
PASSED: [[SimpleTest]]: [MySQL] 200 pass(es). View

Updated patch to change check_plain() to check_markup() based on feedback from Dave Reid.

Also ran a test updating 50 nodes URL aliases via Pathauto with and without the patch and noticed no change in memory consumption, however it may be that Devel can not reliably measure that test. Also ran a test updating 50 nodes URL aliases using the [teaser-raw] token with only a .02M memory increase from the prior 2 tests.

shushu’s picture

David, what stops you from publishing the module out of the sandbox ?
This was the exact module I needed, and it seems to do the work as expected...

David Stosik’s picture

Time and reviews. ;)

kleinermann’s picture

Beautiful! #30 works perfectly for me in combination with the Auto Opengraph module!

David Stosik’s picture

Then you should have a look to that sandbox. ;)

jvieille’s picture

as indicated in#36, notifications provides these tokens.
However, this module does not seem to care about the alledged performance issue.
Here is the code :

 * Implementation of hook_token_list(). Documents the individual
 * tokens handled by the module.
function notifications_content_token_list($type = 'all') {
  $tokens = array();
  if ($type == 'node' || $type == 'all') {
    $tokens['node']['node-teaser']    = t('The node teaser.');
    $tokens['node']['node-body']    = t('The node body.');
    $tokens['node']['node-teaser-raw']    = t('Unfiltered node teaser. WARNING - raw user input.');
    $tokens['node']['node-body-raw']    = t('Unfiltered node body. WARNING - raw user input.');
  if ($type == 'comment' || $type == 'all') {  
    $tokens['comment']['comment-url'] = t('The comment view url.');
    $tokens['comment']['comment-reply-url'] = t('The comment reply url.');
  return $tokens;

 * Implementation of hook_token_values()
function notifications_content_token_values($type, $object = NULL, $options = array()) {
  switch ($type) {
    case 'node':
      if ($node = $object) {
        $values['node-teaser'] = !empty($node->teaser) ? check_markup($node->teaser, $node->format, FALSE) : '';
        $values['node-body'] = !empty($node->body) ? check_markup($node->body, $node->format, FALSE) : '';
        $values['node-teaser-raw'] = !empty($node->teaser) ? $node->teaser : '';
        $values['node-body-raw'] = !empty($node->body) ? $node->body : '';
        return $values;
    case 'comment':
      if ($comment = (object)$object) {
        $values['comment-url'] = url('node/'. $comment->nid, array('fragment' =>'comment-'. $comment->cid, 'absolute' => TRUE));
        $values['comment-reply-url'] = url('comment/reply/'. $comment->nid .'/'. $comment->cid, array('absolute' => TRUE));
        return $values;

This does not seem to have any performance impact on page load (5000 nodes)