+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Alt text thumbnails news

Alt text thumbnails news

5 posts, 0 answered
  1. Rene
    Rene avatar
    25 posts
    Registered:
    02 Feb 2009
    29 Jun 2010
    Link to this post
    Hi,
    In the newsitems we use in the list thumbnails for every newsitem. Unfortunately the alt-text isnot shown, which means that the W3C validotor gives errors. How can we solve this?

    René
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    29 Jun 2010
    Link to this post
    Hello Rene,

    There are two options

    1. Map external templates ( How to map an external template) ListPageMaster.ascx and ListPageDetail.ascx and add empty alt attribute ( alt="") to the ASP.NET Image control

    2. Get the alt tag from the Image uploaded to Images and Documents module. You have to create a custom control that inherits from NewsView and override SetItemMetadata. You have to get the image item ( content item) by ID and get the AlternateText metakey.

    sample code

    protected override void SetItemMetadata(Control itemContainer, IContent contentItem)
           {
               base.SetItemMetadata(itemContainer, contentItem);
             
               string thumbValue - (string)contentItem.GetMetaData("Thumbnail");
     
               string id = thumbValue.Substring(value.IndexOf("]") + 1);
               var libraryManager = new LibraryManager(LibraryManager.DefaultContentProvider);
               IContent cnt = libraryManager.GetContent(new Guid());
               string altText = (string)cnt.GetMetaData("AlternateText");
               Control ctrl = base.FindContentViewControl("Thumbnail", itemContainer);
                   if ( (ctrl != null) && (ctrl is System.Web.UI.WebControls.Image)
                    {
                           
                          ((System.Web.UI.WebControls.Image)ctrl).AlternateText =  altText;
                    }
                
     
           }


    Sincerely yours,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Sachin
    Sachin avatar
    18 posts
    Registered:
    10 Nov 2010
    09 Feb 2012
    Link to this post
    Hi Ivan, 
    I am using the first option of mapping external template. I have added AlternateText attribute to Image control.

    <asp:PlaceHolder ID="ThumbnailHolder" runat="server">
                    <p class="sf_newsThumbnail" style="margin:0px;" >
                        <asp:Image ID="Thumbnail" runat="server" AlternateText="" style="float: left; margin:0 10px 0 0 !important; width:100px; height:auto; "  /></p>
                </asp:PlaceHolder>

    For the thumbnail of news item I am simply passing the url of the image in the library which already has alternate text added to it.
    newsContent.SetMetaData("Thumbnail", tempImageUrl)

    But text still doesn't show on the alt of thumbnail in the news list. Am I missing something?
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    10 Feb 2012
    Link to this post
    Hi,

    Have you set the AlternateText property from the server side code as my post shows?

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Sachin
    Sachin avatar
    18 posts
    Registered:
    10 Nov 2010
    13 Feb 2012
    Link to this post
    Thanks Ivan, I was having some other issues. I finally got it working! 
    For those having interested, here is my code of the custom control. 

    Imports System.Web.UI
    Imports Telerik.News.WebControls
    Imports Telerik.Cms.Engine
      
    <ToolboxData("<{0}:CustomNewsView runat=server></{0}:CustomNewsView>")>
    Public Class CustomNewsView
        Inherits NewsView
      
        Public Overrides Property ItemListTemplatePath() As String
            Get
                Return "~/Sitefinity/ControlTemplates/News/ListPageMaster.ascx"
            End Get
            Set(ByVal value As String)
                         'No need to set anything. We are only using this property to read the path.
            End Set
        End Property
      
        Public Overrides Property SingleItemTemplatePath() As String
            Get
                Return "~/Sitefinity/ControlTemplates/News/ListPageDetails.ascx"
            End Get
            Set(ByVal value As String)
                   'No need to set anything. We are only using this property to read the path.
            End Set
        End Property
      
        Protected Overrides Sub SetItemMetadata(ByVal itemContainer As Control, ByVal contentItem As IContent)
            MyBase.SetItemMetadata(itemContainer, contentItem)
            Dim libraryManager As New Telerik.Libraries.LibraryManager()
            'Get the thumbnail url from news item.
            Dim newsItem_thumbValue As String = DirectCast(contentItem.GetMetaData("Thumbnail"), String)
            Dim thumbValue As String = newsItem_thumbValue.Split("/").Last
            'Remove the image extension from thumbnail value.
            Dim thumbName As String = thumbValue.Substring(0, thumbValue.Count - 10)
            'Get the library item with the name of thumbnail.
            Dim filter As New List(Of Telerik.Cms.Engine.IMetaSearchInfo)()
            filter.Add(New Telerik.Cms.Engine.MetaSearchInfo(Telerik.Cms.Engine.MetaValueTypes.ShortText, "Name", thumbName))
            Dim cnt As System.Collections.IList = libraryManager.GetContent(filter(0))
            If cnt.Count > 0 Then
                Dim altText As String = TryCast(cnt(0).GetMetaData("AlternateText"), String)
                Dim ctrl As Control = MyBase.FindContentViewControl("Thumbnail", itemContainer)
                If (ctrl IsNot Nothing) AndAlso (TypeOf ctrl Is System.Web.UI.WebControls.Image) Then
                    TryCast(ctrl, System.Web.UI.WebControls.Image).AlternateText = altText
                End If
            End If
        End Sub
    End Class

Register for webinar
5 posts, 0 answered