On our user page (/user/12345) we want to change the profile image field to be a media library reference field instead. I've created for the user object a new field called field_profile_image that is an entity reference/media library reference.

In my twig template for this user page I can display the full rendered user image in the default display mode with a bunch of extraneous information by using {{ content.field_profile_image }}

What I would like to do is display just the image at 136x156 (a media display mode I've set up), preferably with an alt tag.

I've tried various solutions with or without twig tweak, and am still having trouble showing just the referenced image with an alt tag.

Note that I see a lot of examples for twig tweak have something like {% set media_uri = node.field_media|file_uri %} {% if media_uri is not null %} {{ media_uri|image_style('thumbnail') }} {% endif %}

but node is null since this is not on a node, and replacing node.field_media with content.field_profile_image in the above script doesn't render anything at all.

How can I display a media library image in a particular display mode preferably with alt tag?

1 Answer 1


but node is null since this is not on a node

In user template there is {{ user }} variable wich holds user entity. So just replace "node" with "user" in your snippets.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.