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

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

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

2 posts, 0 answered
  1. Glen
    Glen avatar
    2 posts
    Registered:
    24 Apr 2015
    15 Dec 2016
    Link to this post

    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?

  2. Victor Leontyev
    Victor Leontyev avatar
    65 posts
    Registered:
    01 Jul 2014
    10 Jan in reply to Glen
    Link to this post

    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);
    }

     

2 posts, 0 answered