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

Forums / Developing with Sitefinity / Adding a new field in the News Module

Adding a new field in the News Module

5 posts, 0 answered
  1. Femy
    Femy avatar
    37 posts
    Registered:
    02 Jan 2008
    09 Oct 2008
    Link to this post
    OK I am stuck with another issues on the News module. I want to create a new field called URL that is the URL of the full article where the News appeared. I followed your directions in the users Manual for creating a subtitle field as an eg and updated the web.config/ControlPanelEdit.ascx and ControlPanelInsert.ascx. I created a new News Item and the new field is show in the Edit View.
    1)I saved the News module but when I go to the page with the News Details Page, I dont see the new field displayed.
    2)When I go to the Edit the Page- NewView-Edit - I dont see the new field in the News Settings where I can check it.
    How can i get this working. Pls help.
    TIA
    FR
  2. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    09 Oct 2008
    Link to this post
    in addition to adding the input field to the Edit and Insert controls on the admin side, you also need to add the output label to the SingleNews (assuming that's the view you're using, there is also a ListPageDetails in the Modes folder). Assuming you called the field URL add a Hyperlink control and make sure that the ID matches:

    <asp:HyperLink ID="URL" runat="server" /> 

    if i recall correctly the sitefinity system should automatically locate this control and fill it with your field. if it doesn't, be sure that you also added this field to the web.config file as an extra metafield:
     
    <metaFields> 
        <!-- other fields --> 
        <add key="News.URL" valueType="ShortText" visible="True" searchable="False" sortable="False" defaultValue=""/>  
    </metaFields> 

    i hope that this was helpful!
  3. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    09 Oct 2008
    Link to this post
    Hello Femy,

    Please refer to the following topic of the Developer Manual which describes how to add a new meta field to Generic Content module and display it in the details of the ContentView control: Example: Extending Content View Control. By analogy with this, you should achieve the required functionality for the NewsView control.

    Do let us know if you need any further assistance.


    All the best,
    Pepi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  4. Femy
    Femy avatar
    37 posts
    Registered:
    02 Jan 2008
    10 Oct 2008
    Link to this post
    Thx I got this working.

    Now I have another issue. I have created a text field for the URL where the user can input a link. Now on the actual page, I would like to have the link clickable. How do I get this?

    FR
  5. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    13 Oct 2008
    Link to this post
    Hello Femy,

    You need to do the following:
    1. Open ~/Sitefinity/ControlTemplates/News/Modes/ListPageDetails.ascx template and add HyperLink control that will display the url:

    <p> 
        <asp:HyperLink ID="URL" runat="server" /> 
    </p> 

    4. Create your own NewsView control (NewsViewExtender
    ) that inherits from the base NewsView class and override SetItemMetadata method like this:

    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; 
    using Telerik.Web; 
     
    namespace Telerik.News.WebControls 
        public class NewsViewExtender : NewsView 
        { 
            protected override void CreateChildControls() 
            { 
                base.CreateChildControls(); 
            } 
     
            protected override void SetItemMetadata(Control itemContainer, IContent contentItem) 
            { 
                base.SetItemMetadata(itemContainer, contentItem); 
     
                HyperLink url = itemContainer.FindControl("URL"as HyperLink; 
                if (url != null
                { 
                    string navigateUrl = contentItem.GetMetaData("URL"as string
                    url.Text = navigateUrl; 
                    url.NavigateUrl = navigateUrl; 
                }  
            } 
        } 
     

    5. Register your custom control in the <toolboxControls> section of the web.config file to display it in "Add Controls" toolbox:

    <add name="NewsView Extender" section="News" type="Telerik.News.WebControls.NewsViewExtender, App_Code" /> 

    Please explain in details if there is some misunderstanding.

    Kind regards,
    Pepi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Register for webinar
5 posts, 0 answered