How to get categories and tags from shared content block
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
Hi,
To get the categories of an item, you need to use:
GetValue<
TrackedList
<Guid>>("Category")
GetValue<
TrackedList
<Guid>>("Tags").
controls.GetValue<
TrackedList
<Guid>>("Tags")
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);
Hello Ricardo,
I am glad to hear that you managed to get the categories. Thank you for sharing your solution.
Regards,
Stefani Tacheva
Telerik