How to get the parent entity title inside image.html.twig I want to get the node title inside an image.html.twig override so I can use it to replace the 'title' and 'alt' attributes of the image.
So far I was able to pass simple variables with THEME_preprocess_image(&amp;$variables) but no luck getting the title of the parent node.
The cleanest solution that I could find is to get node object in image-formatter.html.twig which is a wrapper to image.html.twig.

Add THEMENAME_preprocess_image_formatter to your THEMENAME.theme

function THEMENAME_preprocess_image_formatter(&amp;$variables) {
  $variables["node"] = $variables['item']-&gt;getEntity();
}


Copy core/themes/classy/templates/field/image-formatter.html.twig into your THEMENAME/templates directory.  

Now you can get the node title in this twig file using {{node.getTitle()}} or {{node.label()}} 

The twig file might look like this

Node title: {{node.getTitle()}}

{% if url %}
  &lt;a href="{{ url }}"&gt;{{ image }}&lt;/a&gt;
{% else %}
  {{ image }}
{% endif %}


Don't forget to rebuild cache (clear cache) for the changed hooks/twig files to be seen by your Drupal installation.

Alternatively if you want to just change the alt and title attributes of your image based on the node title here is one way to do it (covers question in the comments)

function THEMENAME_preprocess_image_formatter(&amp;$variables) {
  $node = $variables['item']-&gt;getEntity();
  $variables["image"]["#alt"] = $node-&gt;label();
  $variables["image"]["#title"] = $node-&gt;label();
}