1

I have an content type called Image that has two fields: Title and Image

I have a Views block created so that it displays the images I want based on my criteria.

What I need is to have the raw image URL available.

Example:

/sites/default/files/background1.jpg

I found this article Rendering Drupal 7 fields (the right way) and quite frankly, I am at a loss.

From the Drupal API:

field_view_field($entity_type, $entity, $field_name, $display = array(), $langcode = NULL)

I know I have to code the views-view-fields--my_custom_view.tpl.php, but everything I do results in an error.

What needs to go in this file so that I can simply get the URL from the image that I am looking for?

Also point in the right direction to a tutorial would be great. Everything I have found assumes you are an expert in Drupal and at this point, everything feels circular.

2

I was able to do this strictly using Views by creating a relationship to the File Entity.

I have detailed this in another post which can be found here Getting the URL from an Image (or Any File).

This eliminates the need for a URL Formatter module and is D8 compatible out of the box.

  • This works, but I have a problem with versioning: now the relationship with the file collects all the files in the version history, not just the current published revision. So I end up with lots of duplicates for each node. Any idea how to go around this? Thanks! – Óscar Gómez Alcañiz Feb 12 at 13:41
1

Image URL Formatter

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.

I have created a content type, and add an image field instance to it, later i use views to export the data of this content type.And i want to output the data,then i could import it into another drupal 7 site with feeds module. What i need is the url of the image field, but i could not export the image url directly. That is why i create this small module.

Usage

(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.

  • Thanks, I might use this as a last resort, but I am really trying to do this without loading another module. After all, it's only going to be used on one page. – Allan Oct 14 '15 at 5:49
  • Solved it. See my answer. – Allan Oct 15 '15 at 15:21

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.