Add or remove synonyms to tags
When you add synonyms to a tag, you can filter your content items by the tag name or by the tag synonyms. You can, as well, to add or delete synonyms programmatically.
For more information about adding tags via code, see Add and remove taxonomies: Add tags.
You can add tag synonyms in the code-behind of web form, in a custom widget, and so on.
Add synonyms
To add a new synonym:
- Use
TaxonomyManagerwhich is the manager class for taxonomies. - Get the specific taxon with name
Test. - Create a new synonym of type
Synonym. - Define the parent and the value of the synonym created.
- Call the manager’s
SaveChangesmethod to persist the changes to the database.
Following is an example of the code:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Telerik.Sitefinity.Taxonomies;
using Telerik.Sitefinity.Taxonomies.Model;
namespace Telerik.Sitefinity.Documentation.CodeSnippets.DevGuide.SitefinityEssentials.Taxonomies.Tutorials
{
public partial class TaxonomiesTutorialsSnippets
{
public static void AddTagSynonym()
{
//gets an instance of the TaxonomyManager
TaxonomyManager taxaManager = TaxonomyManager.GetManager();
//get the taxa by name
var taxa = taxaManager.GetTaxa<FlatTaxon>().Where(t => t.Name == "Test").Single();
//creates a synonym
var synonym = taxaManager.CreateSynonym();
//set the value of the synonym and the tag that it is associated with
synonym.Value = "value goes here";
synonym.Parent = taxa;
//always call SaveChanges in order to finish the operation
taxaManager.SaveChanges();
}
}
}
Remove synonyms
To remove a synonym:
- Use
TaxonomyManagerwhich is the manager class for taxonomies. - Lookup the synonym by value.
- Call the manager class
Deletemethod. - Call the manager class
SaveChangesmethod to persist the changes to the database.
Following is an example of the code:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Telerik.Sitefinity.Taxonomies;
namespace Telerik.Sitefinity.Documentation.CodeSnippets.DevGuide.SitefinityEssentials.Taxonomies.Tutorials
{
public partial class TaxonomiesTutorialsSnippets
{
public static void RemoveTagSynonym()
{
//gets an instance of the TaxonomyManager
TaxonomyManager taxaManager = TaxonomyManager.GetManager();
//gets the synonym by value
var synonym = taxaManager.GetSynonyms().Where(s => s.Value == "value goes here").FirstOrDefault();
//deletes the synonym
taxaManager.Delete(synonym);
//call SaveChanges method in order to finish the operation
taxaManager.SaveChanges();
}
}
}
Want to learn more?
Enhance your Sitefinity skills by enrolling in free training sessions. Become Sitefinity certified through Progress Education Community to strengthen your professional credentials.
Get started with Integration Hub | Sitefinity Cloud
This free lesson teaches administrators, marketers, and other business professionals how to use Sitefinity Integration Hub to create automated workflows between Sitefinity and other business systems.
Web Security for Sitefinity Administrators
This free lesson teaches administrators the basics about protecting your Sitefinity instance and your sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.
Foundations of Sitefinity ASP.NET Core Development
The free on-demand video course teaches developers how to use Sitefinity ASP.NET Core and take advantage of its decoupled architecture and modern development model.