+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Space-separated list of classifications / taxonomies

Space-separated list of classifications / taxonomies

4 posts, 0 answered
  1. Josh Anderson
    Josh Anderson avatar
    48 posts
    Registered:
    15 Dec 2005
    06 Jan 2014
    Link to this post
    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>

    I tried using the FlatTaxonField control, but it creates a UL for the classifications. I tried specifying my own layout template, but it gives me an "object reference not set to an instance of an object" error when rendering the control.
     
    I'd like to be able to do this via the list template rather than developing a custom widget if possible.
  2. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
  3. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    06 Jan 2014 in reply to Steve
    Link to this post
    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
  4. Josh Anderson
    Josh Anderson avatar
    48 posts
    Registered:
    15 Dec 2005
    06 Jan 2014
    Link to this post
    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 "";
        }
    }

    To use this in my custom module list, you just need to do something like this:

    <div class='isotopeItem <%# Container.GetTaxonomyNameList("propertyname", " ") %>'>
        [Standard binding stuff]
    </div>
4 posts, 0 answered