3

I'm trying to add the alt text from a cck image field in a Drupal 7 node template. Getting the image style url is done, but I can't figure out how to just get the alt text. This is what I have

<img src="<?php print image_style_url('160x160', $node->field_image['und'][0]['uri']); ?>" alt="????" class="thumbnail" />

How does one just output the alt text?

1
  • does a print_r($node->field_image, TRUE) or its equivalent shed any light on it?
    – Jimajamma
    May 14, 2013 at 14:12

2 Answers 2

1

If you install the Devel module, you'll be able to use:

<?php dpm($node); ?>

It will provide all available fields that you could use. Another method might be to use theme('image') to help clean up your image theming.

0

A print_r will give you idea. In your case it will be

$node->field_image['und'][0]['alt']

ie: <img src="<?php print image_style_url('160x160', $node->field_image['und'][0]['uri']); ?>" alt="<?php echo $node->field_image['und'][0]['alt']; ?>" class="thumbnail" />

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.