0

I want to include Magnific Popup in my site. The only thing that left to do is display the URL of the image in link wrapping the image field.

I saw that image.html.twig modify the image of my articles. So, the override works but when I try to use some variables it just don't work (only atributtes and style_name are allowed).

What can I do if I want to display the URL of $var['elements']['field_image']['#blazy']['_uri'](Kint)?

Here is the twig template that I trying to modify:

{#
/**
 * @file
 * Theme override of an image.
 *
 * Available variables:
 * - attributes: HTML attributes for the img tag.
 * - style_name: (optional) The name of the image style applied.
 *
 * @see template_preprocess_image()
 */
#}
<a href="#" class="popup-img"><img{{ attributes }} /></a>

UPDATE: If I try to use {{ attributes.src.__toString() }} as advised in comments of this post, I see this output, not the image data:image/svg+xml;charset=utf-8,%3Csvg xmlns%3D&#039;http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg&#039; viewBox%3D&#039;0 0 640 257&#039;%2F%3E

  • What about {{ attributes.src }}? – sonfd Mar 8 '20 at 4:54
  • {{ atributes.src }} displays data:image/svg+xml... not the link that I want. – renguer0 Mar 8 '20 at 5:00
  • 1
    {{ attributes.src.__toString() }} shows me the relative image URL. – No Sssweat Mar 8 '20 at 5:55
  • @renguer0 are you using svg image module? maybe that changes the output for src. – No Sssweat Mar 8 '20 at 6:12
  • No, I'm using blazy with responsive style. With __toString() is still showing this weird output data:image/svg+xml;charset=utf-8,%3Csvg xmlns%3D&#039;http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg&#039; viewBox%3D&#039;0 0 640 257&#039;%2F%3E – renguer0 Mar 8 '20 at 6:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.