New!
Import instagram posts as nodes automatically with the instagram importer module for drupal 8 & 9.

 

Jan 08, 2020 in Drupal 8, Snippets

Helper snippet to render images with an image style in drupal 8. Read more about Render arrays in drupal 8 here.

$imageUri = isset($node->get('field_image')->entity) ? $node->get('field_image')->entity->getFileUri() : null;
if($imageUri) {
  $image = [
    '#theme' => 'image_style',
    '#style_name' => 'medium',
    '#uri' => $imageUri
  ];
  $markup = render($image)
}