I modified the drupal 'story' content type to add four text fields: "left content", "left content title", "right content" and "right content title". I used CCK blocks to place the "left content" and "right content" fields into the left and right sidebars, respectively, and, in configuring the blocks, I used tokens in the titles to try to display the corresponding titles.

The bug is that the token substitution works correctly for only one of the two CCK blocks. The other displays the token (in brackets), with no substitution performed.

To try to understand why, I replaced each of the tokens in the two CCK block titles with the token '[type]'. Then the token replacements work in both titles, but, while the type displayed in the first CCK block title is (correctly) "story", the type displayed in the second CCK block title is (I think incorrectly) "right content". If I remove (that is, don't display) either one of the two CCK blocks, then the other is displayed correctly (with type "story").

So, somehow, the node being passed for the second replacement is not the story node, but a node with type "right content".

Neal

Comments

Anonymous’s picture

Project: CCK Blocks » Token
Version: 6.x-1.2 » 6.x-1.12
Priority: Normal » Critical

Neal, thank you for your very detailed report.

I reproduced this bug, but it seems to be a bug in the thoken module.

We call the following line for each block:

$block['title'] = token_replace($title,'node',$node);

token_replace seems to work only the first time, we invoke it. It doesn't return a string, when it is ran a second or third time.

Unfortunately, I couldn't figure out the problem in the token module. Therefore I'm asking the developers of that module for help by moving this to the token modules issue list.

Anonymous’s picture

Title: tokens in titles fail when more than one CCK block used on a page » Tokens are not replaced when running token_replace more than once from within the same module
dave reid’s picture

Priority: Critical » Normal
Status: Active » Postponed (maintainer needs more info)

I can't duplicate this, sorry.

$node = node_load(2);
echo token_replace('Node title: [title]', 'node', $node) . "\n";
echo token_replace('Node year: [yyyy]', 'node', $node) . "\n";

Results in:

Node title: Consectetuer Plaga Dignissim Quadrum
Node year: 2010

I'm not sure token.module is at fault here unless more details can be provided.

Anonymous’s picture

Project: Token » CCK Blocks
Version: 6.x-1.12 » 6.x-1.x-dev
Status: Postponed (maintainer needs more info) » Needs review

Thank you for that hint. I checked our code again and found out, that I used a wrong variable that is only initialized the first time, a node is loaded from the database. Dave, I apologize for wasting your time.

Please check the next -dev release in approximately 12 hours.

dave reid’s picture

Hey, good to know it's not a token bug like I thought. Thanks for the report back!

Anonymous’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.