How to get categories and tags from shared content block

Posted by Community Admin on 04-Aug-2018 11:06

How to get categories and tags from shared content block

All Replies

Posted by Community Admin on 26-Jun-2013 00:00

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


Posted by Community Admin on 01-Jul-2013 00:00

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

Posted by Community Admin on 01-Aug-2013 00:00

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

Posted by Community Admin on 01-Aug-2013 00:00

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

This thread is closed