0

This is a bit messy so bear with me. I've built a node with a field collection 'field_meet_videos'. That field collection contains another field collection 'field_about_video'. The inner field collection has 3 fields (two text fields and an image field 'field_image'). This field collection is also used as multifield so it'll be used more than once (lets say 3 times for this example).

What I'm trying to do is just get a printed output of the image url (with imagecache style) on the node template (to use them as html element backgrounds).

<?php
  $content['field_meet_videos'][0]['entity']['field_collection_item'][34]['field_about_video'][0]['entity']['field_collection_item'][35]['field_image']
?>

This looks to contain enough that I could cobble together a url by sticking these variables into a url string but it feels like there must be a better way to access these variables.

1 Answer 1

0

You can find a good example of how to decompose the field_collection with a foreach in drupal.org

https://www.drupal.org/node/1155752#comment-12170687

if (isset($node->field_gallery_images)) {
  $nodeField = field_get_items('node', $node, 'field_gallery_images');
  if (!empty($nodeField)) {
    foreach ($nodeField as $key => $item) {

      $field_collection_item = field_collection_item_load($item['value']);
      $item_wrapper = entity_metadata_wrapper('field_collection_item', $field_collection_item);

      print '<div class="yourCustomClass">';
      $field_image = $item_wrapper->field_gallery_image->value();

      print theme('image_style', array('style_name' => 'large', 'path' => $field_image['uri'])); 
      print '</div>';
  }
}

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.