Find news widget control by category settings?

Posted by Community Admin on 04-Aug-2018 15:00

Find news widget control by category settings?

All Replies

Posted by Community Admin on 14-Jun-2011 00:00

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

Posted by Community Admin on 15-Jun-2011 00:00

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

Posted by Community Admin on 16-Jun-2011 00:00

Awesome, thanks Ivan.

This thread is closed