We use cookies to improve our services and provide a better experience. By continuing to use this site, you agree with our Cookies Policy.

Tutorials

More than 400 step-by-step articles to guide you through online project development.
HomeTutorialsCMS TutorialsDrupalDrupal Administration

How to get the field_image path in Drupal 7

Cloud Servers 727 x 90

For getting images in the node-articles.tpl.php page in Drupal 6, use the following code entry:

1
2
3
4
5
6
7
$cck_images = $node->field_image;
if (count($cck_images)>0) :
foreach ($cck_images as $cck_image) :
$image = theme('imagecache', 'large', $cck_image['filepath'], $cck_image['data']['alt'], $cck_image['data']['title']);
print $image;
endforeach;
endif;

In Drupal 7, which has slightly different structure, there is no [‘filepath’] variable. Therefore, the mentioned code will not be working properly in Drupal 7. In this case we will need to find the solution which would be working with Drupal 7 as well. Instead of the before written code, use this one:

<?php
$image_url = file_create_url($content[‘product:field_image’][‘#items’][0][‘uri’]);
?>

Another way to try this is to use a Drupal module called Devel. Install the module and go to the node.tpl.php file and enter this code at the end:

<?php
dpm($content);
?>

Rate this Tutorial:
No Comments Leave a Comment
Leave a Comment

Cloud Servers 1 230×230

Other (195)

Popular Keywords

Web Banner 2 230×230