Category list is coming back empty for news items in News widget that have categories.
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?
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);