Space-separated list of classifications / taxonomies
I have created a custom module which includes a field for a custom classification which is selected just like tags are. I'm using client-side list filtering via Isotope (http://isotope.metafizzy.co/). In order to accomplish this, I need to render the classification names assigned to each module item as a space-separated text. I've been editing the list template for this custom module, but I can't seem to get it to render a simple space-separated list.
To clarify, let's say I've created a custom module of Widget. I've added a custom classification of WidgetCategory, which is a field for each Widget item. Let's say I have a widget named "Sprocket" that's has categories "Round" and "Steel." I need the list to render something like this:
<
div
class
=
"isotopeItem Round Steel"
>
Sprocket
</
div
>
Would modifying the template of this work?
http://www.sitefinitysteve.com/blog/code/2012/09/15/better-sitefinity-taxonomy-widget-you-should-use-this
Hey John,
I think that you either use the solution like Steve suggested, or create a custom widget. It's more flexible.
I've done quite the same thing using MixItUp on this page: http://www.lightfortheworld.nl/en/what-we-do/projects
Is that what you like to achieve?
Kind regards,
Daniel
Steve's post was a big help, but I couldn't use it as a user control since I needed to append the class listing as a plain string. After playing around with it for a bit, I decided to just do an extension method for the databinding container. Here's what I did:
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
""
;
<
div
class='isotopeItem <%# Container.GetTaxonomyNameList("propertyname", " ") %>'>
[Standard binding stuff]
</
div
>