Adding a custom classification to the built-in Events module
Before I ask how to do this, I'll first ask if it needs to be done. Right now, an Event has a Category field, but as far as I can tell there's no way to segment categories such that you can only choose Event categories in events, and News categories in news items, etc. If there's a way to accomplish that, then the following request is moot (which would be great).
Assuming there isn't a way to do that, I figured I would have to extend the Events module to add my own property. I found this blog post explaining how to extend the module, but it's for a rather trivial string property. If I were to create my own classification ("EventType"), would it possible to follow the same process for a property of type Taxon? If so, how would I be able to specify what type of classification to use? I presume that would be necessary for the entry interface to pick up that it was a classification and allow the user to select from the list.
Or am I going down the wrong road here? Is there an easier way to add a property to an event such that the user can simply pick it, preferably through a drop-down?
Hello,
I think you are looking for custom classifications. Here is documentation on the topic: http://www.sitefinity.com/documentation/documentationarticles/user-guide/website-content/classifying-your-content/creating-custom-classifications
When you have created a new classification you can add a custom field to Events. http://www.sitefinity.com/documentation/documentationarticles/user-guide/website-content/adding-custom-fields-to-content-items
The custom field should be of type "Classification" and then the UI will allow you to select your new custom classification.
Regards,
Boyko Karadzhov
Telerik
That did it for the classification, thanks. I didn't see it because I didn't have any events set up, so those options weren't shown.
It prompts another question, though -- is it not possible to add an image field to events and news? In custom modules I can ass a "media" field type, but I don't see that in the event custom field types.
Update...
I found this post, which indicates in 6.0 and 6.1 image selectors aren't supported, but the last answer indicates it can be done. Any chance someone from Telerik can chime in on whether this workaround is advisable or if I should just stick to a string field with the URL?
Hello,
Would you please open another thread for the custom field with media? This thread's title is about classifications and it would be more convenient for the community to see the custom field solution in its dedicated forum thread.
Here are some related links that can save you some time in the meantime:
A blog post that shows how this can be done: http://www.sitefinity.com/blogs/slavoingilizov/posts/slavo-ingilizovs-blog/2011/09/09/extend_the_image_selector_for_content_items_with_filtering_by_album
Also there is a PITS logged to make it out of the box: http://www.telerik.com/support/pits.aspx#/public/sitefinity/14322
Regards,
Boyko Karadzhov
Telerik
I created another thread as requested with some details on the thumbnail question.
However, on the note of the custom classification added to an event, I'm having trouble displaying those classifications in my template. If I just do an Eval("PropertyName") I get Telerik.OpenAccess.TrackedList`1[System.Guid] output...presumably the result of a simple .ToString() on the property.
I figured I could use this extension method I had for another purpose:
public
static
class
TaxonomyPropertyExtensions
public
static
string
GetTaxonomyNameList(
this
IDataItemContainer container,
string
propertyName,
string
separator)
var dataItem = container.DataItem;
if
(dataItem !=
null
)
if
(!String.IsNullOrEmpty(propertyName))
var property =
OrganizerBase.GetProperty(dataItem.GetType(), propertyName)
as
TaxonomyPropertyDescriptor;
if
(property !=
null
)
var @value = property.GetValue(dataItem)
as
IList<Guid>;
if
(@value !=
null
)
var manager = TaxonomyManager.GetManager();
return
string
.Join(separator, @value.Select(guid => manager.GetTaxon(guid).Name).ToArray());
return
""
;
<%# Container.DataItem.GetTaxonomyNameList("EventType", "") %>
Hello,
Displaying taxonomies is supported out of the box without additional code.
<
sitefinity:HierarchicalTaxonField
ID
=
"custom"
DisplayMode
=
"Read"
runat
=
"server"
TaxonomyMetafieldName
=
"custom"
TaxonomyId
=
"a0f3887e-630f-6f39-9246-ff0000b04d78"
WebServiceUrl
=
"~/Sitefinity/Services/Taxonomies/HierarchicalTaxon.svc"
AllowMultipleSelection
=
"true"
Expanded
=
"false"
ExpandText
=
"ClickToAddTags"
BindOnServer
=
"true"
/>
Boyko, you're misunderstanding where I'm using that code. This isn't for the designer, it's for actually using the content on a page. When I display news content on the site I need to be able to retrieve a simple string representation of the classification name assigned to the news item. I use this info to specify the class of a badge element and have CSS that appropriately styles that badge element. For example, I use that extension method in this way:
<
span
class='label <%# Container.DataItem.GetTaxonomyNameList("MyClassification", "") %>
<%# Container.DataItem.GetTaxonomyNameList("MyClassification", "") %>
</
span
>
Hello,
The taxonomy field renders the selected classification property as a simple UL tag with each taxon rendered in LI. This is in DisplayMode="Read". It is what is used by default for the frontend. To style it you would need to inherit it or globally change its template. Here is a similar example: http://www.sitefinity.com/blogs/team-blog/2011/07/26/customizing_sitefinity_4_controls_with_the_viewmap
Since you already have the custom code, your solution is far better for the case. Easier to style and does not render anything extra. Thanks for sharing!
Regards,
Boyko Karadzhov
Telerik
The problem is that the code doesn't work on the built-in modules like news and events. It only works on custom modules.
My question is how I can get a simple text representation of the classification assigned to the event. I don't want any HTML markup at all...just the string value.
Hello,
I have tried your code on event with custom taxonomy field and it works. There was just a small mistake in the markup for the template. Your extension method is for the container, not for the data item.
<%# Container.DataItem.GetTaxonomyNameList("EventType", "") %>
I'm an idiot. In the other templates where I use that extension method I run it on the Container. No idea why I did it on the DataItem this time.
Anyway, hopefully the code will be helpful to someone else.