Output a alt value of an image field - drupal

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.

Related

Drupal 7 - Display single image from multiple image field in View

I would like to display just single image from field with multiple upload option enabled in my View. The best would be to display the first uploaded image, but It does not matter.
I have tried to add that galerry field to field, and was looking for some settings that will give me that option to show only specific or some images.
Is it possible in View to display single image from gallery?
From views if you are using views to display you content
There is settings for multiple valued field you can display specific number items or single item
Just click on that field you will find this setting
If you need to control this from your node display
Single Image this module helps you
Thanks

Drupal 7 Views list, add link

Currently I have a Drupal installation which has colorbox installed, this allows me to upload a group of images with some text, each entry is its own entity but are all listed on the same page.
I was just wondering if there is a way that I can display a custom link under each views item (entity). Is this possible?
I'm looking for a quick way to simply add a link that links to the first image of the colorbox image slider.
First, set your Format to Show: Fields. To do so, click the link next to Show: (refer to the picture below) and change it to Fields.
If your Format is set to Show: Fields, you can add a new field of type Global: Custom text. Then, in the text box that appears, simply insert your custom link. If you need to pull in the URL dynamically, use a Replacement Pattern (see the list under the text box).
If you need to use another field as a replacement pattern, add it in the same way as you added the Global: Custom text field but make sure to check the Exclude from display checkbox so that it is not shown in your view.

Add an "image" field to entity "views"

My setup: I'm using Drupal 7 with lots of contrib modules (Chaos Tools, Views, IMCE, etc.) I'm not sure if Views are considered Entities right off the bat, but I'll be asking this question assuming that they are.
My question: How do I add a field to all Views that asks the admin for an image?
The context: I have a sidebar module that lists every View. I need them all to have thumbnails to the left of them.
What I've tried: I've tried looking all over the Field/CRUD APIs but I could not find anything that appends a field called "Image" to the end of the views_view table. I also tried watching some conferences e.g. DrupalCon but I couldn't find anything that was specific to my question.
Don't know exactly what you mean by "asks the admin for an image", but asuming you'd like to add a static image to a view you have the following options:
( probably easiest) add an image tag to a view block template.
If you don't yet have a block template create one in your theme template folder and name it: block--views--{VIEW_BLOCK_DELTA}.tpl.php, copy the contents of the default block.tpl.php into the file and then add the img tag.
Login as admin, go to: structure > views and then click edit on a view you'd like to add image to.
Go to fields section.
Now it depends if you want to use the image path from cck field value OR you want to hardcode it, like you would in the 1st example.
CCK field way: ( first create a cck field of course), add it to your view fields list, go to rewrite result and tick "Rewrite the output of this field" and then add to textarea sometihing like that:
< img src="[YOUR_FIELD_NAME]">
You can also hardcode it, if you don't need it to be stored in a cck field in db:
select a random field, click on it, go to go to rewrite result and tick "Rewrite the output of this field" and then add to textarea sometihing like that:
< img src="trololo.jpg"> [RANDOM FIELD NAME]
This would just append the image next to an existing filed, so with just a little styling you could achieve your goal quite quickly

Drupal based on check box flag, change the textbox text as link or normal text

This what I am expecting:
If the user filled the textbox, and if the user checked means, while displaying the content on that time, content should show as a link, if the user is not checked, then it need not to show the link while that content in view mode. See the following image for an illustration.
Not an exact solution to what you want to do but I believe the Link Module will display only text if no url is entered.
You can give users a message saying to leave URL field blank and only enter a TITLE if they want plain text.
UPDATE:
You don't need to code any hooks. The CCK Module adds fields to content types. The Link Module adds link functionality to CCK.
No coding is necessary; this can all be done from the admin panel. If you have no idea what I'm talking about see this video.
http://drupal.org/project/conditional_fields module does exactly what you are trying to accomplish. You can use the link_field of cck along with the conditional fields module. So based on the value in the check-box you can choose to display it in the node view.

Drupal: CCK ImageField, multi-line description

I'm using CCK Image field (multi-images) and for each image I have the "Description" field, where I can add the image description.
I was wondering if I can have multi-line description, instead of only one line.
(Even using some specific symbol to go next line)
thanks
If you are wanting a textarea instead of a textfield for the image description field, the only way to do this would be to create a custom module that creates a compound field. There is a really great tutorial on the state of compound fields in Drupal and how to create one here: http://poplarware.com/articles/cck_field_module.
Alternatively, if you only have one image you are uploading, you could disable the description on the image field and create an additional CCK textarea to be used as the description.
When you create CCK imagefield, there is a setting called "Title text settings", where you can set the checkbox "Enable custom title text" and select Input type: textarea instead of textfield.
So now there is nothing you must to specially to make a multiply description for your every imagefield.

Resources