Category list is coming back empty for news items in News wi

Posted by Community Admin on 05-Aug-2018 21:41

Category list is coming back empty for news items in News widget that have categories.

All Replies

Posted by Community Admin on 15-Dec-2016 00:00

Hi

We are customizing the List.NewsList.cshtml bootstrap feather view for the News widget, and trying to retrieve the categories for the news item.

According to things we have read, we should be able to do the following (the @foreach was already in the view)

 @foreach (var item in Model.Items)
           
                var newsItem = (Telerik.Sitefinity.News.Model.NewsItem)item.DataItem;
                var categoryList = newsItem.GetValue<TrackedList<Guid>>("Category");

However, categoryList is coming back with zero items in the collection. We know the items have categories.

Any ideas?

Posted by Community Admin on 10-Jan-2017 00:00

Hi Glen, 

You  can access category field like that item.Fields.Category

So,in my case News have"sectors" taxonomy. And my view is like that:

var taxonomyManager = TaxonomyManager.GetManager();
var sectors = taxonomyManager.GetTaxa<FlatTaxon>().Where(t => t.Taxonomy.Name == "sectors");
var newsSectors = new List<string>();
foreach (var nt in item.Fields.sectors)
          Guid ntId = nt;
          var sector = sectors.First(i => i.Id == ntId);
          newsSectors.Add(sector.Title);

 

This thread is closed