Last active
July 18, 2024 08:31
-
-
Save jamiemagique/e3063fa7cb1ea163a11c to your computer and use it in GitHub Desktop.
Drupal 7 - Render an image using the picture module mappings programatically (via preprocess_node() in this gist)
This file contains hidden or 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
// Get image settings array from a field on the node | |
$image = field_get_items('node', $node, 'INSERT_IMAGE_FIELD_MACHINE_NAME'); | |
// Picture settings | |
$picture_mapping = picture_mapping_load('INSERT_PICTURE_MAPPING_MACHINE_NAME'); | |
$fallback = 'INSERT_IMAGE_STYLE_MACHINE_NAME'; | |
$breakpoints = picture_get_mapping_breakpoints($picture_mapping, $fallback); | |
// Create a new variable to pass through to the node template | |
$variables['INSERT_NEW_VARIABLE_NAME_TO_PASS_TO_NODE_TEMPLATE'] = theme('picture', array('uri' => $image[0]['uri'], 'style_name' => $fallback, 'breakpoints' => $breakpoints)); |
It saved my time! Thanks!
Thanks a lot!
It's great! Thanks! :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks! :)