20

We were working with Drupal 7 and trying to rewrite the views output

We need the src of the image field , not the whole image tag.

Clicking on

Rewrite the output of this field

[field_first_image] : Gives the whole content ie with tag ,

We tried to display the below ones

[field_first_image-fid] == Raw fid

[field_first_image-alt] == Raw alt

[field_first_image-title] == Raw title

But the same ( [field_first_image-fid] ) thing is displayed in the view. Is there a way we can get the src from the views rewrite ?

Hari K T
  • 4,174
  • 3
  • 32
  • 51

4 Answers4

24

If you don't want to need to install a module for this, there is a solution.

  • Create a new relationship
  • Select your image field (this will create a relationship to the file entity)
  • Add a field to your view
  • Select File: Path
  • Check Display download path instead of file storage URI

Note that this will create a URL to the original image, not to an image produced when applying an image style (like cropping, resizing etc.) so this may not work in every scenario.

aross
  • 3,325
  • 3
  • 34
  • 42
  • To get the uri of the file just don't check the `Display download path instead of file storage URI`. – yunzen Jul 15 '14 at 14:50
  • If you wan't internal link (public://), you have to uncheck it. If you want the full path, you need to check on this option.. So it's a correct! This worked for me! – Finduilas May 11 '17 at 13:23
18

Image URL Formatter

This module add a url formatter for image field. Then you can output image url directly.

maestro888
  • 301
  • 2
  • 6
10

You can get the file name by changing the field as shown in the attached image.

Formatter: Rendered file

View mode: Tokens (or Link will work - depending on what modules you have installed)

Strip HTML tags (checked)

You'd then need to do a Rewrite Output with the server's public file location in front of the token [field_first_image]. That'll get you the full SRC.

There's probably a better way to do this though... Depending on the final thing you're attempting to create.

Views settings

Christopher Cooper
  • 1,910
  • 4
  • 20
  • 25
  • I don't really know whether this is right answer for I don't play with Drupal now adays. If your answer is right I can mark it as yes. So for that I will wait for some one to vote for the answer. If anyone gets a vote I will surely mark it as right. So I/you don't write something wrong. Hope that makes sense. Thank you once again for the answer. – Hari K T Dec 01 '12 at 13:56
1

One possibility is to create a custom field formatter for the image field and use this formatter in the set-up of the view.

In your case, the custom image field formatter shall only return the source of the src of the image.

You can use this great tutorial to create a custom field formatter : http://www.computerminds.co.uk/articles/creating-new-field-formatters-drupal-7

Laurent
  • 440
  • 1
  • 4
  • 11