0

I am working with Drupal 8 and trying to print some fields through a twig file.

Created:

  1. A view (format:grid)

  2. A content type (fields: title, body image)

  3. Contents

File working on:

  1. views-view-fields--[machine-name].html.twig

To Do:

  1. How can I print the path of the image in the content?

  2. How can I print the path of the node/content on a Read More link?

0

To get the path of an image in a view, use the image format 'URL to Image' in the field setup. I have not found a really good way to get the site absolute, rather than relative url, but prefixing the returned value in a rewrite block with {{ url'(<front>') }} is almost there:

{{ url'(<front>') }}{{ field_image }}

To use that in a different field (content), mark it 'Excluded from display' and then reference that field using a rewrite in another field, or using a twig field template.

0

Q: How can I print the path of the image in the content? A: I got the file path of image by printing the image field directly in twig. Like: {{ fields.field_sliding_image.content }}

Q: How can I print the path of the node/content on a Read More link? A: I added a path field in my view and then in twig I did the following: Like: {{ fields.path.content }}

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.