0

I have a field collection field_plaats_en_aantal with two fields: field_plaats (text) and field_aantal (integer). I'm currently displaying this field collection in a node view as an unordered list:

Unordered list

I'd now like to theme the field collection a bit in order to get something like this instead:

New display

It seems fairly easy, but I can't find a way to achieve this. At first, I tried to work with a template file views-view-field--field-plaats-en-aantal.tpl.php, but I don't know how to grab the values of the field collection items there. Is this a good way to work on? If yes, how can I get the needed values?

Afterwards, I read some things on the internet about templates for the field collection items themselves and tried using two templates field-collection-item--field-plaats.tpl.php and field-collection-item--field-aantal.tpl.php, because that seemed an easier solution to me. However, those files aren't scanned and therefore don't affect the theming of the fields. What am I doing wrong?

2
  • You can do literally all of that with CSS...
    – Clive
    Commented May 6, 2015 at 12:47
  • @Clive: Yes, I've achieved what I want by using the default classes. Thanks for the motivating hint. :)
    – Jeroen
    Commented May 6, 2015 at 13:32

1 Answer 1

0

It turned out that I was making things too complicated: the theming can be achieved with CSS by using the default classes of the field collection. Hopefully, my code underneath can be helpful for others too.

.item-list li {
  list-style: none;
}

.field-name-field-plaats:before {
  content: "@ ";
}

.field-name-field-plaats {
  display: inline;
}

.field-items {
  display: inline-block;
}

.field-name-field-aantal:before {
  content: " (";
}

.field-name-field-aantal:after {
  content: "x)";
}

.field-name-field-aantal {
  display: inline;
}

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.