Drupal - How can I get image url in a views field, D8

When setting up your view, under the advanced section you can create a relationship for the image field.

After you added the relationship, you can then add a File URI field, select the created relationship and you are good to go.


This is the magic, without the "Image URL Formatter" module:

  1. You have to add a relationship in your view to your image field (It's under Advanced)
  2. Now you can add a 'File URI' field to your fields
  3. In your views-view-fields.html.twig template (Or one of the appropriate alternatives for your specific view) add this:

{{ file_url(fields.uri.content|striptags|trim) }}


Is the module "Image URL Formatter" maybe helpful for you? https://www.drupal.org/node/1162614/release?api_version%5B%5D=7234

There is a second one: https://www.drupal.org/project/image_raw_formatter

I never did a feature comparison to find out which is the better one ...

Tags:

Views

8