1

I am creating a frontpage image scroller. I have created a new content type with a title, blurb and image field, and created a view block and set it up on the frontpage. All good so far; this works.

I obviously want to use some javascript and custom HTML to create the image scroller so I have overwritten the views 'row style output' template (views-view-fields--content-type-for-scroller--block.tpl.php). This template is getting picked up correctly and I can customize my 3 fields.

The problem is that the output from the image field:

$fields['myimage_field']->content

includes markup for the image, similar to:

<div class="..."><a href="..."><img src="..." />

whereby I only want it to output the Image src so that I can use the image as a background to another element.

I'm not too familiar with Drupal 7 but I image somewhere 'further up' I need to overwrite what sort of output I want for that particular field using some preprocessor but I'm not sure how to do this? Or is there a better way in general to be doing this?

1

here two alternatives to get the image address: (to both examples the machine name of the image field is *image_test_field*).

1) this example is using the $row offer by view template (in this case the name of the field was obtained using dsm($row) or print_r($row)):

  $uriImagefromView = $row->field_field_image_test_field[0]['rendered']['#item']['uri'];
  $urlImagefromView = file_create_url($uriImagefromView);
  // $urlImagefromView variable now has the path to the image

2) this example is loading the data from entity_load (in this case the name of the field was obtained using dsm($entity) or print_r($entity)):

  $nid = $row->nid;
  $entity = entity_load('node', array($nid));
  $uriImagefromNode = $entity[$nid]->field_image_test_field['und'][0]['uri'];
  $urlImagefromNode = file_create_url($uriImagefromNode);
  // $urlImagefromNode variable now has the path to the image

I hope this information be useful.

  • The first option worked perfectly. Thanks very much. – Timmy O'Mahony Sep 19 '11 at 14:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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