The image formatter has only one option: Image. I would like to get the URL, not the full markup, for a field output.
Do I need to make a custom formatter? Also, I don't see any way to rewrite the text using tokens to get the image URL.
The image formatter has only one option: Image. I would like to get the URL, not the full markup, for a field output.
Do I need to make a custom formatter? Also, I don't see any way to rewrite the text using tokens to get the image URL.
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:
{{ 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 ...
Overwrite result, with the next twig code:
{{ uri | image_style('thumbnail') }}
Where uri is the token of the File URI field and thumbnail is the desired image style.
Here is my solution that doesn't require a relationship:
This gives you an output like this:
<a href="http://domain/path/to/file.jpg" ...
{% if field_image|trim is not empty%}
{{ field_image|split('"')[1] }}
{% endif %}
This splits the string on the "
character and the index of 1 is your url in the href. It is kinda hacky but this actually gave me what I wanted. Going the relationship route I could only ever get a link with public:/path/to/file.jpg
not the absolute URL