This technique is used quite a lot to get an image styled url of an image in your twig file.

use Drupal\image\Entity\ImageStyle; // on top

function THEMENAME_preprocess_node(&$vars) { 
   if(($node->getType() == 'partner_logo') && ($variables['view_mode'] == 'teaser')) {
    $id = $node->field_logo->entity->getFileUri();
    $url = ImageStyle::load('partner')->buildUrl($id);
    $variables['image_url'] = $url;

Then, in your partner-logo--teaser.html.twig:

<div style="background-image:url('{{ image_url }}'); background-size: cover"></div>





Saved you some valuable time?


Donate and get more free time-saving code on this website in the future.