Add or remove synonyms to tags

This article contains
NEW TO SITEFINITY?

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:

  1. Use TaxonomyManager which is the manager class for taxonomies.
  2. Get the specific taxon with name Test.
  3. Create a new synonym of type Synonym.
  4. Define the parent and the value of the synonym created.
  5. Call the manager’s SaveChanges method to persist the changes to the database.

Following is an example of the code:

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:

  1. Use TaxonomyManager which is the manager class for taxonomies.
  2. Lookup the synonym by value.
  3. Call the manager class Delete method.
  4. Call the manager class SaveChanges method to persist the changes to the database.

Following is an example of the code:

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?

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Get started with Integration Hub | Sitefinity Cloud | Sitefinity SaaS

This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.

Web Security for Sitefinity Administrators

This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its 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 .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?