1

In a node template, how would I be able to get the URL from an image field? Like if it were something like this:

{{ content.field_image.URL }}

Or if there is a similar alternative perhaps?

0

Have you seen the answer of this question?

| improve this answer | |
0

{{ content.field_image[0]['#item'].target_id }} would return the file entity id.

{{ content.field_image[0]['#item'].getUploadLocation() }} would return the file upload location uri (public://image-1)

It is better to use a preprocess function for this kind of logic and pass the result as a variable.

| improve this answer | |
  • How would one do that? I've been trying to accomplish this but I keep getting an undefined variable error. – ForsakenCreator Nov 30 '15 at 9:02
0

Getting the URL in a way that is actually a URL is not so easy and I think can currently only be done in preprocess. You need something like this:

enter code herefile_create_url($variables['node']->field_image->entity->getFileUrl())

| improve this answer | |

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.