i need something like

<img attribute1='value' src='sites/default/files/styles/thumbnails/**pic_0**.jpg'>

in views.

i have to use rewrite result because i need attribute1. but i have no idea how to get src of image. [filename] is not always same with file path. -for example [filename] is pic.jpg but file path is pic_0.jpg- .

and [uri] give me http://example.com/sites/default/files/pic_0.jpg not http://example.com/sites/default/files/styles/thumbnails/pic_0.jpg.

how can i get pic_0.jpg or http://example.com/sites/default/files/styles/thumbnails/pic_0.jpg?

  • Is this a regular image field you're displaying in your view? That doesn't typically have [uri] as a replacement token... May 10, 2013 at 19:49

2 Answers 2


You can get file path of image style in view.tpl


 * field with image: "field_image"
 * uri:  (image from field_image) File: Path

$style_name = $view->field['field_image']->options['settings']['image_style'];
$thumb_path = image_style_url($style_name, $uri);

I didn't wrote how to get $uri because it depends on type of template file. The general idea is to get a file path of image style by using image_style_url($style_name, $uri) in view.tpl file.

  • Doing logic and loading things in templates is ugly.
    – Elin Y.
    Feb 28, 2016 at 9:23

You can achieve that by using Image URL Formatter module.

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

Most of the code, maybe more than 90%, is just copy from the drupal core. I think it is stable enough.


  1. After install this module,then you add an image field,then you can goto this bundle's manage display page,here at format column,you can choose "Image URL" instead of "Image".
  2. When you add an image field in your views,then you config the Formatter for this field, here you can choose "Image URL" instead of "Image".

Then you can output image's URL instead of Image itself.

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.