Last active
December 20, 2016 11:34
-
-
Save thebrainroom/4547d4f99e1203cd8e9491498a453cae to your computer and use it in GitHub Desktop.
Get image style programmatically for Drupal 8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Drupal\image\Entity\ImageStyle; | |
function blissgo_preprocess_node(&$variables) { | |
$node = $variables['node']; | |
if(!empty($node->field_image[0])) { | |
$path = $node->field_image->entity->getFileUri(); | |
$url = ImageStyle::load('teaser_image')->buildUrl($path); | |
$variables['teaser_image_url'] = $url; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment