More in this section

Forums / Developing with Sitefinity / Extending the News Module

Extending the News Module

7 posts, 0 answered
  1. Simon
    Simon avatar
    31 posts
    Registered:
    01 May 2009
    05 Jun 2009
    Link to this post
    Hi,
    I have a requirement to extend the news module. I'm using the external news templates: ListPageMaster.ascx and ListPageDetials.ascx.
    I need to add a drop down list to the admin section and then pass the selected item to the ListPageMaster.ascx control in order to append it as a query string to the news item url.
    So I need to:
    1. Add the control to the NewsItemNew and NewsItemEdit controls and access the contents of the drop down list, presumably on the click event of saveButton1.
    2. Add the selected value to a new property along with all the other news properties.
    3. Access that property from the ListPageMaster control and append it to the news content url.

    I'm not sure of the best way to go about this within Sitefinity.

    Thanks for you help.

    Simon
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    06 Jun 2009
    Link to this post
    Hi Simon,

    You can add the controls to the template as metakeys so that you will persists their value. I think your approach should work. If you get stuck write back to us.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Simon
    Simon avatar
    31 posts
    Registered:
    01 May 2009
    08 Jun 2009
    Link to this post
    Hi,
    Thanks for you reply.
    I have added an extra meta field to my NewsItemNew.ascx control and can capture the value I enter which is then displayed in the details section along with "Author", "Summary" etc.
    However I cannot seem to access this value from with my LisPageMaster.ascx control.
    I named my control "Playlist" in the web.config:
    <add key="News.Playlist" valueType="Integer" visible="True" searchable="True" sortable="True" defaultValue=""></add> 

    and referenced it within the news list page along with the other meta fields:
    <asp:literal id="Playlist" runat="server"></asp:literal> 
    <asp:Literal ID="Author" runat="server"></asp:Literal>              
    <asp:Literal ID="Source" runat="server"></asp:Literal>     
    <asp:HyperLink ID="Category" runat="server" /> 

    The "Playlist" value is not displayed on the page. What am I missing? Is there a way to access this "Playlist" meta field from with the code behind file without adding it to a display control within the html? I need to append the value to the url of the news story as a query string.

    Many thanks for your help.
    Simon.
  4. Simon
    Simon avatar
    31 posts
    Registered:
    01 May 2009
    08 Jun 2009
    Link to this post
    Hi,
    Just a follow up...
    I can access the new meta field that I've added via ListPageMaster.ascx.cs by calling the GetMetaData method, however I'm stuck as to how I can append this value to the url of my IContent news item in order to pass it as a query string to the ListPageDetails page.
    It would seem I need to add the query string to newsItem.UrlWithExtension, however this is obviously a read only property. Is there a specific way to go about appending the query string?

    Many Thanks.

    Simon
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    08 Jun 2009
    Link to this post
    Hello Simon,

    To append a metakey value to the item url you need to override the control and GetUrl method as the example below illustrates.

    public class MyNewsViewControl : NewsView 
        public MyNewsViewControl() 
        { 
        } 
     
        public override string ItemListTemplatePath 
        { 
            get 
            { 
                return "~/Sitefinity/ControlTemplates/News/ListPageMaster.ascx"
            } 
        } 
     
        private string itemListTemplatePath; 
     
        protected override string GetItemUrl(Telerik.Cms.Engine.IContent contentItem, string singleItemUrl) 
        { 
            string url = base.GetItemUrl(contentItem, singleItemUrl) + "?id=" + contentItem.GetMetaData("MyPlaylist").ToString(); 
            return url; 
        } 
     
        protected override string GetItemUrl(Telerik.Cms.Engine.IContent contentItem, string singleItemUrl, bool resolveLanguageUrl) 
        { 
            string url = base.GetItemUrl(contentItem, singleItemUrl, resolveLanguageUrl) + "?id=" + contentItem.GetMetaData("MyPlaylist").ToString(); 
            return url; 
        } 
     


    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  6. Simon
    Simon avatar
    31 posts
    Registered:
    01 May 2009
    09 Jun 2009
    Link to this post
    Ok, great, so assuming I add the "MyNewsViewControl" to the App_Code folder the GetItemUrl method should be overridden and return the url + the query string?
    Do I need to do anything else in order for the links within my ListPageMaster control to implement this overridden method?

    Thanks

    Simon
  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    09 Jun 2009
    Link to this post
    Hello Simon,

    You need to register the control in your web.config <toolboxControls> section.

    <add name="MyCustomNewsViewControl" section="News" type="MyNewsViewControl, App_Code" description="this is my custom control" /> 

    The code works fine, so the only thing that you could change is how the link will be formed and which metakey you want to get.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Register for webinar
7 posts, 0 answered