I set up a custom module to use the token hooks. Everything works great, until the page using tokens is edited. In the edit text box, the literal value is displayed and not the token. So on a save, the token is lost.

Any way to prevent this?

Im defining my tokens like this in my custom module:

function tcftokens_token_values($type, $object = NULL) {
    switch($type) {
        case 'global':
            $values["Total One"]              = variable_get('mytoken-total_one', 0);
            $values["Total Two"]              = variable_get('mytoken-total_two', 0);

Thanks.

Comments

emackn’s picture

I realize I left out "return $values" ..

I also call the tokens like this in my content:
The First Total is [Total One].

eaton’s picture

It sounds like you're doing token_replace() when you SAVE your content, rather than when you VIEW your content. Is there a way to see a bit more context for this code?

emackn’s picture

Ahh, thats probably the reason, I'm calling token_replace on $content inside page.tpl.php.
My first guess is that I need a conditional around the token_replace, but is there a more efficient way I should be using token_replace?

Thanks.

eaton’s picture

Status: Active » Closed (works as designed)