Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > Can categories be inherited? View modes: 
User avatar
Member
Member
eric.savage-clyral - 1/24/2013 9:49:13 AM
   
Can categories be inherited?
We are thinking of using categories to define broad areas of a site, so that all child pages can be identified as belonging to an area of the site.

However, we don't want to have to assign the categories to each new page, so inheritance would be helpful. Is this possible, or is there a better way of achieving the desired behaviour?

User avatar
Kentico Consulting
Kentico Consulting
richards@kentico.com - 1/25/2013 4:05:06 AM
   
RE:Can categories be inherited?
Hello,

sadly the inheritance of categories is not yet impelemnted in Kentico. You could create a custom handler that would be activated when a new page is created and that would check the parent category and set it to this newly created page. This however requires custom coding so there isnt any easier way.

Sorry for the inconviniences.

Best regards,
Richard Sustek

User avatar
Member
Member
davids-kentico - 1/25/2013 5:10:22 AM
   
RE:Can categories be inherited?
Here you go - add this as a new class in your App_Code folder. It's not inheritance per se, but it does what you need. It copies the categories from the parent document when you insert a new document.

See Global handlers to learn more about this customization approach.

using CMS.DocumentEngine;
using CMS.SettingsProvider;

[CustomDocumentEvents]
public partial class CMSModuleLoader
{
/// <summary>
/// Attribute class that ensures the loading of custom handlers
/// </summary>
private class CustomDocumentEventsAttribute : CMSLoaderAttribute
{
/// <summary>
/// Called automatically when the application starts
/// </summary>
public override void Init()
{
// Assigns custom handlers to the appropriate events
DocumentEvents.Insert.After += Document_Insert_After;
}

private void Document_Insert_After(object sender, DocumentEventArgs e)
{
DocumentHelper.CopyDocumentCategories(e.Node.Parent.DocumentID, e.Node.DocumentID);
}
}
}

User avatar
Member
Member
eric.savage-clyral - 1/25/2013 6:30:06 AM
   
RE:Can categories be inherited?
Thanks for the input.

Searching by categories is the way we might go. I was looking at this article to see how to then search by categories, although I'm wondering if there's a simpler way.
http://devnet.kentico.com/Knowledge-Base/Search/How-to-search-for-documents-using-assigned-categor.aspx

Alternatively I was looking at the option of searching by path instead, but based on this article we can't search by a combination of paths (only by searching either all paths or one specific path):
http://devnet.kentico.com/FAQs/Web-parts-Controls/How-to-use-multiple-paths-on-a-web-part-.aspx

Is there some way to modify the Where clause on the search results web part to know the path of the indexed document - is that an inbuilt solr field or would we need to add it as an additional searchable field on the doc type and then populate as per this article?
http://devnet.kentico.com/Knowledge-Base/Search/How-to-search-for-documents-using-assigned-categor.aspx

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 2/7/2013 3:45:55 AM
   
RE:Can categories be inherited?
Hi,

the FAQ and KBs you are refering to are pretty old and I think you are looking at it in a too complicated way.

In v7 in the smart search you can use search condition to specify the node alias path or you can even set the index to search only in specified path or not to search in given paths.
Or, in the search condition you can use the categories field name - assuming that the document will have the categories added to the field.
Or, you can even create a custom index in v7 that will index things you want in the way you like.

Best regards,
Juraj Ondrus