I am looking to set the ALT attribute of the IMG tag created by DDBlock. I am even OK if all the images in the slideshow use the same ALT value.

Thanks.

Comments

ppblaauw’s picture

Version: 6.x-1.x-dev » 6.x-1.0-rc6
Status: Active » Postponed (maintainer needs more info)

Depends on what functionality you use:

Basic slideshow option:
Images from a folder: Only if you add it in the template file for all slideshows for all images.
Other options: yes

Advanced slideshow option:
Alt text of imagefield: yes

Please let me know what functionality you use of the dynamic display block module.

jrosen’s picture

I am currently using the Basic slideshow option - Images from a folder.

I have not really looked into the Advanced option yet.

ppblaauw’s picture

Your only option is:

  • copy the file: ddblock-cycle-block-content.tpl.php from the ddblock module directory to the directory of the theme you use
  • adjust the value for the alt text of the images. (it's a space now)
  • you could use some php code to make e.g. image 1, image 2 etc. as "alt" text

Hope this helps you further, please let me know

dgautsch’s picture

I think the easiest thing to do is to add a title filed through cck that's associated with your image. I believe it's an option with imagefield. I'd look into that before you go edit the php.

ppblaauw’s picture

Issue tags: +Basic Slideshow

@logicalriot

When using the basic slideshow option with image from a folder it doesn't have to be an image from filefield. It can just be an image uploaded via FTP. There is no alt property with images from a folder.

The only option is adding it in the the template file ddblock-cycle-block-content.tpl.php in your theme.

In the issue is stated: I am looking to set the ALT attribute of the IMG tag created by DDBlock. I am even OK if all the images in the slideshow use the same ALT value.

Adding the alt value to the template file is really the easiest option to do this.

jrosen’s picture

@ppblaauw:

Thanks for pointing me in the right direction...

I changed the ALT value to the following:

alt="<?php print ucwords(str_replace(array("_","-"), " ", pathinfo($image_file, PATHINFO_FILENAME))); ?>"

It takes the image filename, replaces any underscores (_) or dashes (-) with spaces and capitalizes the first letter of each word in the filename. For example, it takes "my_product_name_photo_1" and converts it to "My Product Name Photo 1".

I find this very useful for SEO purposes and think it would be a good addition to the ddblock code.

Can you add this change in to the codebase?

Thanks,
Jason

ppblaauw’s picture

Title: Is there a way to set the ALT attribure for images? » Basic slideshow: Give a default value for ALT attribure for images instead of space?
Status: Postponed (maintainer needs more info) » Postponed
Issue tags: +theming

Jason,

Will implement your solution in next version of the module.
(Better to have a default value than a space.)

Until then you can theme it yourself in the template file (described in #3) if needed.

Thanks for the snippet.

Changed the Issue text
Add a tag

dgautsch’s picture

hi ppblaauw so how would you do this with the advanced slide option when you use file_field to define a custom ALT text?

I've tried entering this code into the template.php but it doesn't seem to work. Maybe I'm going about this wrong:

$result->field_image_data['alt']

ppblaauw’s picture

The alt text of an image field is stored as serialized data. You can get the data with e.g.

   //  add slide_text variable from imagefield description
    if (isset($result->node_data_field_gallery_image_field_gallery_image_data)) {
      $data=unserialize($result->node_data_field_gallery_image_field_gallery_image_data);
      if (isset($data['title'])) {
        $vars['slider_item']['slide_text'] = $data['title'];
      }
    }

Uncomment the drupal_set_message line in the preprocess functions and you will see the image field data field_name. In the example above it is: node_data_field_gallery_image_field_gallery_image_data. Replace it with the field_name of your image field.

Like above you need to unserialize the data and then use the $data['alt'] variable instead of the data['title'] variable like above.

Hope this helps you further, please let me know.

If you can not make it work, please attach your template.php file and the result of the drupal_set_message debug lines, so I can help you better.

dgautsch’s picture

Thanks again, that was what i was missing. I didn't realize i had to unserialize the data. Shortly after I posted my previous post, i found the data field_name i was missing. Thanks again!

dgautsch’s picture

Status: Postponed » Fixed

Status: Fixed » Closed (fixed)
Issue tags: -theming, -Basic Slideshow

Automatically closed -- issue fixed for 2 weeks with no activity.