Output a alt value of an image field
In my Drupal 7 site, I have an image field called field_photos where users can upload an unlimited number of images, plus an alt description for each one.
I would like to print the alt description as caption for the image. How can I do this?
I know that I have to use my tpl.php file, but I am note sure which variable to use represent the alt value of an image field (开发者_开发问答especially when a field can have an unlimited number of values).
You should be able override theme_image_formatter() which is called in image_field_formatter_view().
You do not have to use or edit any .tpl.php file. You can access the alt or the title text of the image by doing the following:
- Add another field to your View, your node's image field (yes, again)
- Ignore the label and display options and go to the fieldset: Multiple Field Settings and uncheck the option: Display all values in the same row
- Next, scroll down to the fieldset: Rewrite Results and then click Rewrite the output of this field. Check the Replacement Patterns below and you should see tokens for both alt and title. Use whichever is appropriate.
Works for me!
You can use https://www.drupal.org/project/image_caption_formatter to display the title text of the image as a caption.
精彩评论