Skip to content

Instantly share code, notes, and snippets.

View benmirkhah's full-sized avatar
💭
hello-world

Ben Mirkhah benmirkhah

💭
hello-world
View GitHub Profile
@jamiemagique
jamiemagique / template.php
Last active February 27, 2019 15:23
Drupal 7 - Render an image using the picture module mappings programatically (via preprocess_node() in this gist)
// 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));