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

Forums / Developing with Sitefinity / Find news widget control by category settings?

Find news widget control by category settings?

3 posts, 1 answered
  1. Ian
    Ian avatar
    75 posts
    Registered:
    25 Oct 2010
    14 Jun 2011
    Link to this post
    We have multiple news pages, each set up to display only items from a single category. I'm trying to build URLs to link to the correct page, which I have managed to do for a custom blog widget. However, unlike the BlogPosts, the NewsItems do not have a Parent, and I can't figure out how to get to the right page without adding a custom field to the news items.

    Is it possible to extend the code below to find out which of the NewsView controls i a list of pages has been set to display only news from certain categories?

    var NewsPages = App.WorkWith().Pages().LocatedIn(Telerik.Sitefinity.Fluent.Pages.PageLocation.Frontend)
                .Where(p => p.Page != null &&
                            p.Page.Controls.Where(c => c.ObjectType.StartsWith(typeof(NewsView).FullName)).Count() > 0)
                .Get().ToList();
     
    foreach (var tnp in targetNewsPages)
     {
    var newsViews = (from a in tnp.Page.Controls.Where(p => p.ObjectType.StartsWith(typeof(NewsView).FullName)) select a).FirstOrDefault();
    }

    Thanks
    Ryan
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    15 Jun 2011
    Link to this post
    Hello Ryan,

    When you filter a control through UI to show data from a certain category we update a property called AdditionalFilter of the frontend definition

    Home > ControlDefinition > Views > NewsFrontendList

    The property contains a string similar to this one where we add the taxon name - in my case is "test"


    FieldName":"Category","FieldType":"System.Guid","Operator":"Contains","__msdisposeindex":723},"Name":
    "test","_itemPathSeparator":"_","__msdisposeindex":724}

    You can get is as shown below

    var man = PageManager.GetManager();

                var NewsPages = App.WorkWith().Pages().LocatedIn(Telerik.Sitefinity.Fluent.Pages.PageLocation.Frontend)
                .Where(p => p.Page != null &&
                            p.Page.Controls.Where(c => c.ObjectType.StartsWith(typeof(NewsView).FullName)).Count() > 0)
                .Get().ToList();

                foreach (var tnp in NewsPages)
                {
                    var newsViews = (from a in tnp.Page.Controls.Where(p => p.ObjectType.StartsWith(typeof(NewsView).FullName)) select a).FirstOrDefault();
                   var c = man.LoadControl(newsViews) as NewsView;
    var categoryName = ((Telerik.Sitefinity.Web.UI.ContentUI.ContentViewMasterDefinition)(((Telerik.Sitefinity.Web.UI.ContentUI.ContentView)(c)).masterViewDefinition)).AdditionalFilter.QueryItems[1].Name
                }



    Best wishes,
    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
    Answered
  3. Ian
    Ian avatar
    75 posts
    Registered:
    25 Oct 2010
    16 Jun 2011
    Link to this post
    Awesome, thanks Ivan.
3 posts, 1 answered