开发者

Output a alt value of an image field

开发者 https://www.devze.com 2023-02-10 05:21 出处:网络
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.

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:

  1. Add another field to your View, your node's image field (yes, again)
  2. 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
  3. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消