Hello, I want to use some of the terms from termpath. As you know it outputs it as a "/" seperated string. I had hoped it would be as easy it using the PHP explode command to cherry pick the terms I want. However I can't get it to work.

this doesn't work

<?php
$name=explode("/",[termpath]);
print $name[2];
?>

and nor does this

<?php
$name=explode("/",$node->[termpath]);
print $name[2];
?>

Both give the error

Parse error: parse error, unexpected '/', expecting T_STRING or T_VARIABLE or '{' or '$' in /home/content/c/a/r/carabusonline/html/sites/all/modules/auto_nodetitle/auto_nodetitle.module(177) : eval()'d code on line 2

I know I'm being daft, I just can't figure out how else to do this.
Many thanks for the patience of anyone who answers me :D

Comments

greggles’s picture

Status: Active » Fixed

I believe the problem is that your second argument to it is not the actual token. You have to get tokens before you can use them.

You'll need something like

$node = node_load(arg(1));
$tokens = token_get_values('node', $node);
$name=explode("/",$tokens['termpath']);
print $name[2];

This is something that the tokenize module can do on cck fields. So, perhaps you'll want to look at that module.

matthew_ellis24’s picture

thanks, I thought it might be something like that, but I wasn't sure how to get the actual token variables. Unfortunately I've broken hierarchical select so I can't sort this out till I get that working (as that's where the terms will be coming from).

But thanks for your help, I'll be sure to give tokenize a bash

Thanks
Matt

Anonymous’s picture

Status: Fixed » Closed (fixed)

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

rus032’s picture

Version: 5.x-1.11 » 6.x-1.12

don't work on Token for Drupal 6.
please help.
thx.

rus032’s picture

Status: Closed (fixed) » Active

don't work on Token for Drupal 6.
please help.
thx.

dave reid’s picture

Status: Active » Closed (fixed)

Don't re-open closed issues.