Render media entity image I have a media entity target id and I want to render the image contained in it. I've loaded the media entity using Media::load, I was hoping to use something like render() on some rendererable array that I can extract/generate from that media entity object.
I found a somehow related question here: How to get Media entity image (Entity Reference Field) URL in TWIG theme, using ImageStyle::load, but I want to render the whole image with its defined attributes (alt, title or fields). Any suggestions please?
You need to build a render array
$build = \Drupal::entityTypeManager()-&gt;getViewBuilder('media')-&gt;view(‌$media, $view_mode);

and then place it unrendered in a template, Twig renders this automatically.