0

I have a multi-value field for user statistics (around 18 INT values): the field field_nurse_patients contains 18 integers 0,5,3,3...

Is there a way to get a format like below with tokens? Maybe with the token custom module or programmatically?

Desired output:

points: 0 height: 5 weight: 3

I've tried accessing the individual values like

[current-user:field_nurse_patients:0]
[current-user:field_nurse_patients:0:value]
[current-user:field_nurse_patients:value:0]
[current-user:field_nurse_patients:und:0:value]

None of which allows me to target the individual deltas.

There are a couple of similar (older) questions, but none of them really answers it.

Tokens for multi-valued fields?

What is the correct token for a multi value field?

7
  • Views allows you to get delta information. You could probably add the Fields, exclude them from display, then use Custom text field to output the line you're after.
    – prkos
    Sep 26, 2018 at 22:03
  • Thx for the suggestion. Ive tried it with adding the nurse field and in "multiple field setting" choose "1" (value) to display and choosing the delta for each value. This results in 18 fields and works. Is there a way to use only 2 fields (nurse_patients and custom) and target/display the delta directly in the custom field - this does not work [field_nurse_patients:0], [field_nurse_patients:value:0])?
    – user24957
    Sep 27, 2018 at 7:21
  • It seems from other questions you mentioned that it can be done with tokens through additional modules (entity tokens, custom tokens) outside of Views, so why not try that? Within Views the way you tried it is the way to go, a clever way to control all delta values is by adding the field many times and controlling the multiple values to "count" them one by one. You can't do it with only two fields out of the box, but I haven't tried it with the extra token modules, so I don't know if they expand the Views Tokens list (you can check under Replacement patterns when you install the modules).
    – prkos
    Sep 27, 2018 at 20:51
  • I forgot to add that in this particular case it makes the most sense to hold nurse info in a Field collection drupal.org/project/field_collection because each of your values is different, it's not just another instance of the same quality. A multivalued field has just one label and it applied to all values. You have different labels/qualities for each of the integers, they aren't the same data.
    – prkos
    Sep 27, 2018 at 21:21
  • Ive entity tokens installed - it doesnt show the delta. I looked a bit into the custom tokens module (drupal.org/node/1280424). I was just hoping that there would be some kind of ready or two code line-solution. i like multi-value fields as they are more lightweight (compared to 18 individual stats fields) and can be easily manipulated with rules. but i see now that display can be cumbersome. tried the field_collection a (long) while back but am hesitant to use it on a production site as i got a few error messages.
    – user24957
    Sep 28, 2018 at 7:12

1 Answer 1

1

You can get to the delta values of multi-value fields with the help of Compound token (it doesn't have to be a compound token, it can be something like [node:field_test:und:1:value]).

As you've already figured out you need Token filter to evaluate tokens in Textarea fields, such as Views Headers or Footers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.