Alt and title in image

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
15 years ago
Hi to all

Why not to add alternate text to image if we have just one image (or non images )
Modules/ProductInfo.ascx in Category too
===============================================================================


if (productPictures.Count > 1)
        {
          defaultImage.ImageUrl = PictureManager.GetPictureUrl(productPictures[0].PictureID);
                    defaultImage.AlternateText = product.Name;
                    defaultImage.AlternateText = product.Name;

                    defaultImage.ToolTip = product.Name;
                    
          rptProductPictures.DataSource = productPictures;
          rptProductPictures.DataBind();
        }
        else if (productPictures.Count == 1)
        {
          defaultImage.ImageUrl = PictureManager.GetPictureUrl(productPictures[0].PictureID);
                    //Alex
                    defaultImage.AlternateText = product.Name;
                    defaultImage.ToolTip = product.Name;

                    //@Alex

                    rptProductPictures.Visible = false;
        }
        else
        {
          defaultImage.ImageUrl = PictureManager.NoImageURL;
          rptProductPictures.Visible = false;
                    //Alex
                    defaultImage.AlternateText = product.Name;
                    defaultImage.ToolTip = product.Name;

                    //@Alex
        }
================================================================================

P.S
Great for SEO.
Thanks
15 years ago
Hi, it's already been implemented for next release. If I get chance this weekend I will post the changes required for both product and caregory images.
15 years ago
:) Good work.
15 years ago
To implement I did the following:

Add following resource strings (english):


IF NOT EXISTS (
    SELECT 1
    FROM [dbo].[Nop_LocaleStringResource]
    WHERE [LanguageID]=7 and [ResourceName] = N'Media.Product.ImageAlternateTextFormat')
BEGIN
  INSERT [dbo].[Nop_LocaleStringResource] ([LanguageID], [ResourceName], [ResourceValue])
  VALUES (7, N'Media.Product.ImageAlternateTextFormat', N'Picture of {0}')
END
GO

IF NOT EXISTS (
    SELECT 1
    FROM [dbo].[Nop_LocaleStringResource]
    WHERE [LanguageID]=7 and [ResourceName] = N'Media.Category.ImageAlternateTextFormat')
BEGIN
  INSERT [dbo].[Nop_LocaleStringResource] ([LanguageID], [ResourceName], [ResourceValue])
  VALUES (7, N'Media.Category.ImageAlternateTextFormat', N'Picture for category {0}')
END
GO

IF NOT EXISTS (
    SELECT 1
    FROM [dbo].[Nop_LocaleStringResource]
    WHERE [LanguageID]=7 and [ResourceName] = N'Media.Product.ImageLinkTitleFormat')
BEGIN
  INSERT [dbo].[Nop_LocaleStringResource] ([LanguageID], [ResourceName], [ResourceValue])
  VALUES (7, N'Media.Product.ImageLinkTitleFormat', N'Show details for {0}')
END
GO

IF NOT EXISTS (
    SELECT 1
    FROM [dbo].[Nop_LocaleStringResource]
    WHERE [LanguageID]=7 and [ResourceName] = N'Media.Category.ImageLinkTitleFormat')
BEGIN
  INSERT [dbo].[Nop_LocaleStringResource] ([LanguageID], [ResourceName], [ResourceValue])
  VALUES (7, N'Media.Category.ImageLinkTitleFormat', N'Show products in category {0}')
END
GO


Most of the images are created using asp:hyperlink controls so you will need to set the ToolTip property (this will give you the link title) and the Text property (this will give you the image alt text).

e.g.



hlImageLink.ToolTip = String.Format(GetLocaleResourceString("Media.Category.ImageLinkTitleFormat"), category.Name);
hlImageLink.Text = String.Format(GetLocaleResourceString("Media.Category.ImageAlternateTextFormat"), category.Name);


The reason for having two resource strings is you may want to display the tooltip text "Show details for the product PRODUCT NAME" but have "Picture of PRODUCT NAME" for the image alt text - for accessibility reasons (screenreaders etc.)


You need to do this on:

/modules/ProductBox1.ascx.cs
/modules/ProductBox2.ascx.cs
/modules/HomePageCategories.ascx.cs
/templates/Categories/ProductsInGrid.ascx.cs
/templates/Categories/ProductsInLine1.ascx.cs
/modules/RelatedProducts.ascx.cs
/modules/ProductInfo.ascx.cs
/modules/ProductVariantsInGrid.ascx.cs

Think that's all of them.

Ben
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.