Build a custom tagger for Sitecore Content Tagging
The tagger for Sitecore Content Tagging is responsible for tagging generic type T items. The tagger takes an item of type T and a collection of Tags objects as input, and then it assigns tags to the item.
This topic describes how to:
Implement a custom tagger
You must implement the generic T parameter, which is an object that you are going to tag, and an input parameter for a method. In the default scenario, T will be an Item.
To create a custom tagger:
-
Implement the generic
Sitecore.ContentTagging.Core.Providers.ITaggerinterface as in the following example:RequestResponsepublic class ExampleTagger : ITagger<Item> { public void TagContent(Item contentItem, IEnumerable<Tag> tags) { // assign tags to your item here var semanticField = (MultilistField)contentItem.Fields["__Semantics"]; contentItem.Editing.BeginEdit(); foreach (var tag in tags) { if (ID.TryParse(tag.ID, out ID id) && !semanticField.TargetIDs.Contains(id)) { semanticField.Add(tag.ID); } } contentItem.Editing.EndEdit(); } }
Add the tagger provider to the configuration file
To use your provider in a content tagging configuration:
-
Register the provider in the configuration file, as in the following example:
RequestResponse<contentTagging> <providers> <tagger> <add name="ExampleTagger" type="Custom.ContentTagging.Core.Providers.ExampleTagger, Custom.ContentTagging.Core" /> </tagger> </providers> </contentTagging>