Closed (fixed)
Project:
Field collection
Version:
7.x-1.0-beta3
Component:
Miscellaneous
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
3 Feb 2012 at 15:38 UTC
Updated:
17 Mar 2015 at 13:44 UTC
Jump to comment: Most recent
Comments
Comment #1
donpwinston commentedI've been trying to do something similar. I have a field collection with image, caption, and credits fields. The only way I can control the output is to create a template for the content type it is used in. Using the field template technique is not feasible for me because all you get to work with is the $content variable. You need the actual cck field arrays. A new formatter is also not practical or very complicated. You might be able to get a field template to do what you want. Create a template file with the name field-collection-item-{field_name}.tpl.php. I do not know where or how you can get the appropriate "page number" from here with just the $content variable.
So to do what you want create a image-caption.inc file that prints the appropriate image and caption on the desired page. There should be some way to determine the page to assign the appropriate value to a variable like $page_no from the $node variable in the template. Then do something like the following: (Mine is a little more complicated then necessary for you. My code creates a photo gallery for a field collection field)
in your node content type template hide your field collection field and include the above.
Comment #2
donpwinston commentedExcuse me. I messed some things up. The Drupal documentation is frgging maddening. The template file name should be field--field-photo-gallery.tpl.php (copy from module/field directory) or you might be able to use field-collection-item--field-photo-gallery.tpl.php. (Copy this and rename to your field from the field_collection module directory)
The comments inside these template files provided by Drupal and the field_collection module are wrong about the naming conventions used.
Comment #3
jmuzz commentedTheme support for field collection is an ongoing issue. See #1157794: Move markup to template files and improve theming in new 2.x branch.
A custom formatter seems like a good option. You can use the custom formatters module to add a formatter using the UI, but you'll still be using PHP code. Similarly you can use display suite and create a custom field, probably a code field.