6

In D7, it seems the token for fields (e.g., [node:field_date]) just returns the rendering of the field. So if the field is multi-valued, this token returns all the values rendered together. However, I'd like to be able to access specific delta values of the field separately using tokens, e.g. using [node:field_date:0] or similar syntax. I also want to be able to chain the token, e.g. [node:field_date:0:long].

Has this been done before? My solution would be to use hook_token_info_alter to mark the field's token as dynamic, then do my own parsing in hook_tokens_alter. But if I do this, will I lose the ability to chain the token?

0

3 Answers 3

1

Have you tried Entity Tokens? It's part of Entity API module.

There are long discussions about date tokens: Date issue about date tokens and Entity Token issue about multi-value field tokens.

1
  • It seems it does require the patch from drupal.org/node/2126215 to get it work, doesn't it? Commented Apr 29, 2015 at 4:16
0

For Date fields there are 3 available values to use...

[node:field-date:value] = Start date [node:field-date:value2] = End date [node:field-date:duration] = Well... Duration. :-) 

/marcus

2
  • Thanks but that's not what I'm looking for. In a multi-valued field_date, I'd like to access value 1, value 2, value 3, etc. Commented Nov 29, 2012 at 19:20
  • Sorry. Then I would assume that something like [node:field_foo:value:?] where ? is the Delta. But it seems to only work for taxonomy term parents... :-( Commented Nov 30, 2012 at 10:03
0

I found I needed to use the Compound Token module for this.

Works with vanilla Token:

[node:field_my_field] 

Throws errors with vanilla Token; Works after installing Compound Token:

[node:field_my_field:und:0:value] 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.