Adding Tags to dynamically created content
We have custom event, blog post and news item forms that automatically tag the content with tags based on who the users is.
I'm reviewing the Sitefinity 4.x api and I've found the EventManager and Event classes and how to create events using the API, I however cannot find anything about Tags in the API. How to I add tags via codebehind?
-Jon
Hi Jon Ingersoll,
Thank you for contacting us!
Sitefinity 4.x introduce the powerful technique of using taxonomies. You could read more about what are taxonomies and how they are applied in Sitefinity here:
http://www.sitefinity.com/40/help/developers-guide/sitefinity-essentials-taxonomies.html
In case you want to use flat taxonomies(e.g. tags), you could look at samples here:
Tihomir,
Thanks for the response, however the example you directed me too appears to have an error. http://www.sitefinity.com/40/help/developers-guide/sitefinity-essentials-taxonomies-associating-items-with-taxa.html).
var taxManager = TaxonomyManager.GetManager();
var taxon = taxManager.GetTaxa<FlatTaxon>().Where(t => t.Name ==
"Book"
).Single();
var contentManager = ContentManager.GetManager();
var allContent = contentManager.GetContent();
foreach
(var content
in
allContent)
content.Organizer.AddTaxa(
"Tags"
, taxon);
The AddTaxa method expects a Guid, not a Taxa or Taxon object. The example should say..content.Organizer.AddTaxa(
"Tags"
, taxon.Id);