Adding tags and categories to content blocks

Posted by Community Admin on 03-Aug-2018 16:10

Adding tags and categories to content blocks

All Replies

Posted by Community Admin on 04-Aug-2011 00:00

I'm working on a website using Sitefinity 4.1, and I was surprised to see you can't add categories or tags to content blocks. Is that not implemented in Sitefinity 4.1?

We've been using Sitefinity 3.X for a couple years now, and we've come to rely on the category/tag functionality for our generic content (and documents). Is this functionality going to be added? The documentation for adding categories states "You can add categories and tags to a content item either when creating it or when editing it", which seems misleading if that only applies to some of the content items.

Thanks,
David

Posted by Community Admin on 05-Aug-2011 00:00

Hello David,

By default, Categories and Tags are removed from Content blocks. But you could use Configurations to add them if you want:

  • Go to Content > Content blocks > Settings (the link in the sidebar)
  • Find Controls > ContentBackend > Views > ContentBackendInsert / ContentBackendEdit > Sections > MainSection > Fields. ContentBackendInsert is the name of the view used to insert content items, while ContentBackendEdit is the view for editing.
  • Create a new HierarchicalTaxonFieldDefinitionElement / FlatTaxonFieldDefinitionElement element. For more details how to set the properties of HierarchicalTaxonFieldDefinitionElement / FlatTaxonFieldDefinitionElement, please refer to News settings (Controls > NewsBackend > Views > NewsBackendInsert / NewsBackendEdit > Sections > TaxonSection > Fields > Category / Tags)

Hope this helps.

Best wishes,
Pepi
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 08-Aug-2011 00:00

Thanks. I'm now able to add tags and categories to the content blocks, but it doesn't appear to save the values. 

I noticed that there are usually tables created to store the values. For instance, the categories for news item appear to be saved in the sf_news_items_category table, and the tags in the sf_news_items_tags table. There doesn't appear to be equivalent tables for content (like sf_content_category and sf_content_tags). 

Any ideas?

Posted by Community Admin on 08-Aug-2011 00:00

Hi David,

You have created the configuration section, but the problems is that you don't have a dynamic field associated with the type that will persist the values you enter. You should create the field programmatically using DynamicData facade or MetaManager and its methods.

Below is a sample code.

App.WorkWith().DynamicData().Type(typeof(Telerik.Sitefinity.GenericContent.Model.Content)).Field().TryCreateNew("mycustomfield", typeof(HierarchicalTaxon)).SaveChanges();

All the best,
Ivan Dimitrov
the Telerik team

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 09-Aug-2011 00:00

I used the code and received the following error:

System.InvalidOperationException was unhandled by user code
  Message=Specified type 'Telerik.Sitefinity.GenericContent.Model.Content' is not a dynamic type.
  Source=Telerik.Sitefinity
  StackTrace:
       at Telerik.Sitefinity.Fluent.DynamicData.DynamicTypeFacade.LoadDynamicType(Type existingType)
       at Telerik.Sitefinity.Fluent.DynamicData.DynamicTypeFacade..ctor(AppSettings appSettings, Type existingType)
       at Telerik.Sitefinity.Fluent.FluentDynamicData.Type(Type existingType)
  (....)

I wasn't sure where to run this code, so I ran it from a ASCX control. 

Posted by Community Admin on 09-Aug-2011 00:00

Hello David,

Try using ContentItem - this is the correct [persistent class used for persisting generic content module items.

If the problem persists you can add the dynamic type using MetaManager class

var metaManager = Telerik.Sitefinity.Data.Metadata.MetadataManager.GetManager();
var type = metaManager.CreateMetaType(typeof(ContentItem));
metaManager.SaveChanges();


All the best,
Ivan Dimitrov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 09-Aug-2011 00:00

It worked after I used the call to CreateMetaType.

Now I'm getting this error when trying to view content blocks on the backend:

Cannot infer MsSql data type from the generic database type ('') / CLR type ('Telerik.Sitefinity.Taxonomies.Model.HierarchicalTaxon') combination given.


[ArgumentException: Cannot infer MsSql data type from the generic database type ('') / CLR type ('Telerik.Sitefinity.Taxonomies.Model.HierarchicalTaxon') combination given.]
   DynamicModule.ns.Wrapped_OpenAccessContentProvider_f6173e24163f4c538aa14fb2b48ee8ef.Initialize(String providerName, NameValueCollection config, Type managerType) +284
   Telerik.Sitefinity.Data.ManagerBase`1.InstantiateProvider(IDataProviderSettings providerSettings, Type providerType, ExceptionPolicyName policy, ManagerBase`1 manager) +2233
   Telerik.Sitefinity.Data.ManagerBase`1.InstantiateProvider(IDataProviderSettings providerSettings, ExceptionPolicyName policy, ManagerBase`1 manager) +117
   Telerik.Sitefinity.Data.ManagerBase`1.SetProvider(String providerName, String transactionName) +691
   Telerik.Sitefinity.Data.ManagerBase`1..ctor(String providerName, String transactionName) +249
   Telerik.Sitefinity.Data.ManagerBase`1..ctor() +37
   Telerik.Sitefinity.Modules.GenericContent.ContentManagerBase`1..ctor() +28
   Telerik.Sitefinity.Modules.GenericContent.ContentManager..ctor() +28

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   Telerik.Sitefinity.Data.ManagerBase.GetManager(Type managerType, String providerName) +277
   Telerik.Sitefinity.Data.ManagerBase.GetMappedManager(Type itemType, String providerName) +125
   Telerik.Sitefinity.Web.UI.ContentUI.ContentView.ResolveContentManager() +321
   Telerik.Sitefinity.Web.UI.ContentUI.ContentView.ResolveDetailItem() +129
   Telerik.Sitefinity.Web.UI.ContentUI.ContentView.CreateChildControls() +63
   System.Web.UI.Control.EnsureChildControls() +102
   System.Web.UI.Control.PreRenderRecursiveInternal() +42
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496

Any ideas?

Thanks again,
David

Posted by Community Admin on 10-Aug-2011 00:00

Hello David,

Here

TryCreateNew("mycustomfield", typeof(HierarchicalTaxon)).SaveChanges(); you need to set the type of the field you want to create - for example string or null.

Regards,
Ivan Dimitrov
the Telerik team

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 10-Aug-2011 00:00

Do you mean using string or null instead of HierarchicalTaxon ?

Here's the code I used:

App.WorkWith().DynamicData().Type(typeof(Telerik.Sitefinity.GenericContent.Model.ContentItem)).Field().TryCreateNew("Category", typeof(HierarchicalTaxon)).SaveChanges();
App.WorkWith().DynamicData().Type(typeof(Telerik.Sitefinity.GenericContent.Model.ContentItem)).Field().TryCreateNew("Tags", typeof(FlatTaxon)).SaveChanges();

Where should I specify the string or null? Also, is string or null the correct option? 

I am trying to look for examples and documentation for these, but I cannot find anything.

Thanks again,
David

Posted by Community Admin on 10-Aug-2011 00:00

I think I have it working. I looked at the database (the sf_meta_fields table) and noticed the News meta fields have a null CLR type, while the taxonomy provider and id columns are set. So I updated the database to reflect those values, and the content and tags appear to be working. 


I'm still curious as to what I should have done. Would this have been better:

App.WorkWith().DynamicData().Type(typeof(Telerik.Sitefinity.GenericContent.Model.ContentItem)).Field().TryCreateNew("Category",null).SaveChanges();
App.WorkWith().DynamicData().Type(typeof(Telerik.Sitefinity.GenericContent.Model.ContentItem)).Field().TryCreateNew("Tags",null).SaveChanges()


This thread is closed