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

Forums / Developing with Sitefinity / How to get categories and tags from shared content block

How to get categories and tags from shared content block

4 posts, 0 answered
  1. Ricardo
    Ricardo avatar
    29 posts
    Registered:
    06 Nov 2012
    26 Jun 2013
    Link to this post
    Hello,

    Wondering if you can help me by showing me how I can get the categories and tags associated with a shared content item.

    At the moment I am getting a list of controls from the placeholder of a specific page.
    var pageManager = PageManager.GetManager();
    var page = pageManager.GetPageNodes().Where(p => p.Title == pageTitle).SingleOrDefault();
    var controls = page.Page.Controls.Where(c => c.PlaceHolder == placeHolder).ToList<ControlData>();

    How do I get the categories and tags of a specific control that will be a shared content block?

    Thanks in advance.

    R


  2. Stefani Tacheva
    Stefani Tacheva avatar
    718 posts
    Registered:
    21 Nov 2016
    01 Jul 2013
    Link to this post
    Hi,

    To get the categories of an item, you need to use:

    GetValue<TrackedList<Guid>>("Category")

    To get tags of an item, you need to use:
    GetValue<TrackedList<Guid>>("Tags").

    For example:
    controls.GetValue<TrackedList<Guid>>("Tags")

    To use the above sample you'll need to add a using Telerik.Sitefinity.Model in your class, to be able to use the extension method GetValue<T>().

    Regards,
    Stefani Tacheva
    Telerik
    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
  3. Ricardo
    Ricardo avatar
    29 posts
    Registered:
    06 Nov 2012
    01 Aug 2013 in reply to Stefani Tacheva
    Link to this post
      Thanks so much Stefani, very helpful. This is how I get the details of it, might be useful for someone else.

    var categories = item.GetValue<TrackedList<Guid>>("Category");
    //get a category ID from the list.
      var catID = categories.FirstOrDefault();
      Guid categoryID = new Guid(catID.ToString());
      var taxonManager = TaxonomyManager.GetManager();
      IList<HierarchicalTaxon> subCategories = taxonManager.GetTaxa<HierarchicalTaxon>().Where(t => t.Id == categoryID).ToList();

    I actually do this within a loop as I go over my items:

    List<Category> catList = new List<Category>();
                    foreach (var i in subCategories)
                    {
                        Category category = new Category();
                        category.title = i.Name;
                        category.parent = i.Parent.Name;
                        catList.Add(category);
                    }
  4. Stefani Tacheva
    Stefani Tacheva avatar
    718 posts
    Registered:
    21 Nov 2016
    01 Aug 2013
    Link to this post
    Hello Ricardo,

    I am glad to hear that you managed to get the categories. Thank you for sharing your solution.

    Regards,
    Stefani Tacheva
    Telerik
    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
4 posts, 0 answered