Adding tags and categories to content blocks
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
Hello David,
By default, Categories and Tags are removed from Content blocks. But you could use Configurations to add them if you want:
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?
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
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.
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();
It worked after I used the call to CreateMetaType.
Now I'm getting this error when trying to view content blocks on the backend:
|
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 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();
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.
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()