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

Forums / Developing with Sitefinity / Customize News ListPageDetails

Customize News ListPageDetails

7 posts, 0 answered
  1. rmoynihan
    rmoynihan avatar
    18 posts
    Registered:
    28 May 2007
    08 Oct 2008
    Link to this post
    Hi,

    I would like to customize the sitefinity user control for displaying a news article.
    This control is located at '~Sitefinity\ControlTemplates\News\Modes\ListPageDetails.ascx'
    I would like to display the thumbnail for the article.

    What do I need to add to the control to display the thumbnail?

    e.g 

    <p class="ImageHolder VideoRight"><img alt="" id="Thumnbnail" /></p>

    Thanks,

    Ronan

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    09 Oct 2008
    Link to this post
    Hi rmoynihan,

    Thank you for using our services.

    ListPageDetails.ascx is not a control. It is a template for NewsView control. To show the thumbnail in the news item details you should create a custom class extending NewsView base class.

    Here are the steps:

    1. Open
    ~Sitefinity\ControlTemplates\News\Modes\ListPageDetails.ascx file.
    2. Add the following declaration to the template:

    <class="sf_newsThumbnail"><asp:Image ID="Thumbnail" runat="server" /></p

    3. Add a new class to App_Code folder inheriting NewsView:

    using System; 
    using System.Data; 
    using System.Configuration; 
    using System.Web; 
    using System.Web.Security; 
    using System.Web.UI; 
    using System.Web.UI.HtmlControls; 
    using System.Web.UI.WebControls; 
    using System.Web.UI.WebControls.WebParts; 
    using Telerik.News.WebControls; 
    using Telerik.Cms.Engine; 
     
    namespace Telerik.News.WebControls 
        public class NewsViewExt : NewsView 
        { 
            protected override void SetItemMetadata(Control itemContainer, IContent contentItem) 
            { 
                // first let's call the base implementation of the SetItemMetadata, so 
                // that it fills the values of all fields it can 
                base.SetItemMetadata(itemContainer, contentItem); 
     
     
                Image thumbnail = itemContainer.FindControl("Thumbnail"as Image; 
                if (thumbnail != null
                { 
                    thumbnail.ImageUrl = contentItem.GetMetaData("Thumbnail").ToString(); 
                } 
            } 
        } 

    4. Register the new control in the <toolboxControls> section of the project web.config file to display it in the toolbox.:

    add name="NewsView Ext" section="Custom" type="Telerik.News.WebControls.NewsViewExt, App_Code" /> 

    Hope this helps.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. rmoynihan
    rmoynihan avatar
    18 posts
    Registered:
    28 May 2007
    15 Oct 2008
    Link to this post
    Ok, Thanks.

    I would also like to add a custom field to the news item  e.g a field which will store a link to a video.

    If I add the textbox to the template where the user can enter the link how can I add this property to the news item so I can use contentItem.GetMetaData("Video") to set or get the value?

    Thanks,

    Ronan
  4. rmoynihan
    rmoynihan avatar
    18 posts
    Registered:
    28 May 2007
    16 Oct 2008
    Link to this post
    Hi,

    I looked further into this and the module I want to customize is the Lists Module but this does not seem to support custom meta fields.

    If I want to add custom fields to a list item e.g link and image fields will I have to create a custom module that inherits from listmodule. If so what classes and controls do I need to create.

    Thanks,

    Ronan
  5. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    20 Oct 2008
    Link to this post
    Hello rmoynihan,

    Currently, the Lists module is not extendable. Custom meta fields could be added only to Generic Content based modules (Generic Content, News, Blogs, Images & Documents and Events). Lists module is not one of them which means that you could not add custom fields to it. The Lists module is based on the relation: title-content and it is not designed with the presumption it would need more fields than that.

    In order to achieve the required functionality, you need to implement a custom module which extends Generic Content and not Lists module. For details refer to the following topic of the Developer Manual: Implementing Generic Content based module

    I hope you'll find this information helpful.

    All the best,
    Pepi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  6. Chris
    Chris avatar
    10 posts
    Registered:
    30 Apr 2008
    20 Mar 2009
    Link to this post
    Hello

    I'm using SF 3.6 and was following this to add an image to the news detail page. I found the following:

    that if you added a asp:Image control with ID="Thumbnail" the imageUrl will be set if there a Thumbnail metadata, if it is blank the page doesn't render.

    I changed the control to ID="ThumbnailImage" and implemented this extended News class with the following change to the SetItemMetadata code (note that itemContainer.Findcontrol... had to become itemContainer.controls(0).FindControl..._)

    Dim thumbnail As Image 
                thumbnail = itemContainer.Controls(0).FindControl("ThumbnailImage") 
                Dim ImageUrl As String 
                ImageUrl = contentItem.GetMetaData("Thumbnail").ToString() 
                If ImageUrl.Length > 1 And Not thumbnail Is Nothing Then 
                    thumbnail.ImageUrl = contentItem.GetMetaData("Thumbnail").ToString() 
                ElseIf Not thumbnail Is Nothing Then 
                    thumbnail.Visible = False 
                End If 

    Let me know if this is the right way to approach this task. Hopefully will help someone else.
  7. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    23 Mar 2009
    Link to this post
    Hi Chris,

    That code works just fine.
    Thank you for sharing it in our forums.

    All the best,
    Georgi
    the Telerik team
    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Register for webinar
7 posts, 0 answered