1

I have a sidebar region "Sidebar Ad" and placed in that region is the custom block "Sidebar Ad" of type "Image" which has two fields "Image" and "Link".

When I output the block on my page using {{ page.sidebar_ad }}, I get the image and the link separate from each other, which is to be expected. What I can't figure out, and I've been trying for around 5 hours now, is how to reference the fields separately so I can wrap the link around the image.

Does anyone know how to reference those fields? Am I going about this the wrong way?

I've successfully pulled the link URL by overriding the specific block template and referencing:

{% block content %}
        <a href="{{ content.field_link.0['#url'].uri }}"></a>
{% endblock %}

Referencing the image URL still eludes me.

  • You say to put field image inside of link field? – Vagner May 4 '16 at 16:36
  • When I do that it keeps the image header on top of the image. I could remove it with styling but I'd prefer to bypass it altogether if possible. – Matthew May 4 '16 at 16:42
1

This was the final solution.

{% block content %}
    <a href="{{ content.field_link.0['#url'].uri }}">
        <img src="{{ file_url(content.field_image.0['#item'].entity.fileuri) }}" alt="{{ content.field_image.0['#item'].alt }}">
    </a>
{% endblock %}

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.