Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
I have a field collection containing an image+caption pair attached to the article content type. You can add one or many to an article. The articles are split into pages using the smart_paging module. I would like to be able to display the first image+caption pair on the first page, 2nd pair on the 2nd page, 3rd on the 3rd, etc.
Do you think the best way to implement this through a custom field formatter? Is there an easier way to configure this behavior through the UI?
Thanks for any ideas....
Comments
Comment #1
donpwinston CreditAttribution: 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 CreditAttribution: 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 CreditAttribution: 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.