Reputation: 7065
In a Drupal 7 .tpl.php file, given an image $some_node->field_image
, how do I fetch the appropriate URL for use in an img src attribute, taking into account the image's style as set in its node's content type's display settings? I have seen the following suggestion, but without any indication where $style
is coming from:
image_style_url($style, $some_node->field_image['und'][0]['uri']);
(the incumbent views are full of these foo['und'][0]bars
by the way, is this really how it's done in Drupal, it seems ridiculous?)
Upvotes: 0
Views: 2538
Reputation: 27013
The $style
is the style name (machine name) of the style you want to apply to the image. You can find all the image styles at ?q=admin/config/media/image-styles
.
See image_style_url for more details.
Example:
image_style_url('large', $some_node->field_image['und'][0]['uri']);
Based on your last comment. I'd suggest you to use field_view_field
.
Example:
$node = node_load(12);
print render(field_view_field('node', $node, 'YOUR_IMAGE_FIELD_NAME'));
Upvotes: 3