Try Now
More in this section
Blogs RSS feed

Filtering dynamic items by custom taxonomy in the front end

by Stoimen Stoimenov
Since the release of the Module Builder we have received number of requests how to filter items by custom taxonomy from the generated widget. Here I am going to show how with very little custom implementation this can be achieved.

First we need to have a dynamic module with a custom classification field, for instance Countries. Refer to Sitefinity documentation how to create one.

All we are going to do is to add a section to the widget designer template that will handle selecting custom taxonomies by which the content is going to be filtered and after that we will register the new widget designer in the settings.

Get the template “DynamicContentSelectorsDesignerView.ascx” that I have attached to this post and add it to your project. In my case I have a folder “Templates” in which the template is copied. Then edit the template as follows:

If you have a hierarchical taxonomy add this “designers” element:

<designers:FilterSelectorItem ID="FilterSelectorItem4" runat="server" Text="By Custom Classification"
                    GroupLogicalOperator="AND" ItemLogicalOperator="OR" ConditionOperator="Contains"
                    QueryDataName="fieldname" QueryFieldName="fieldname" QueryFieldType="System.Guid">
                        <sitefinity:HierarchicalTaxonSelectorResultView ID="HierarchicalTaxonSelectorResultView2" runat="server" TaxonomyId="xxxxx-xxxx-xxxxx-xxxx-xxxx" WebServiceUrl="~/Sitefinity/Services/Taxonomies/HierarchicalTaxon.svc"
                            AllowMultipleSelection="true" HierarchicalTreeRootBindModeEnabled="false">
If you have a flat taxonomy use the following designer:

<designers:FilterSelectorItem ID="FilterSelectorItem4" runat="server" Text="By Geographic Region"
                    GroupLogicalOperator="AND" ItemLogicalOperator="OR" ConditionOperator="Contains"
                    QueryDataName="fieldname" QueryFieldName="fieldname" QueryFieldType="System.Guid">
                        <sitefinity:FlatTaxonSelectorResultView ID="FlatTaxonSelectorResultView1" runat="server" TaxonomyId="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" WebServiceUrl="~/Sitefinity/Services/Taxonomies/FlatTaxon.svc"

Note that the value for TaxonomyId is unique for every application. The easiest way to find it is to add categories widget to a page, edit the widget, delete the value in TaxonomyId field and save then the GUIDs of all of the taxonomies in your application will appear.

QueryDataName and QueryFieldName are the name of the content type taxonomy field. You can find it by editing opening your content type for edit. Just copy the name of the taxonomy field in your module and add it as a value to these properties.
Then go to Sitefinity backend -> Administration -> Settings -> Advanced -> Controls -> ViewMap  and create a new one with the following values:

HostType: Telerik.Sitefinity.Web.UI.ControlDesign.DynamicContentSelectorsDesignerView 

LayoutTemplatePath: ~/Templates/DynamicContentSelectorsDesignerView.ascx (the path to the template)

Save and restart your application. Go to pages, add the dynamic content type widget to a page, edit it and you can see that there is a selector for your custom taxonomy. Select some taxons, save and you can view that only items with that taxon are displayed.

Here is the template that should be used.


Leave a comment
  1. Stacey Aug 30, 2012
    Nice information.  This sure beats having to go into FilterExpression.  To anyone following this please watch if pasting the ViewMap information.  You will want to make sure you cut out any trailing spaces or you will not be able to save the new ViewMap.

    Also make sure to strip out the commented text in the template or your widget designer will throw an error when trying to parse the new template.

  2. Beth Feb 06, 2013

    Should this still work for 5.3 or is there something else that has to be done? 

  3. Beth Feb 06, 2013

    I figured it out... if you have a space in the title like "Management Teams", Sitefinity will default the developer name to "management-teams". This will throw a Object is not a reference error. To fix this you need to change the developer name of the Classification to something without a hyphen. I chose "managementTeams". It seemed to work after that just fine.

  4. John Oct 24, 2013
    I'm trying to figure out how to register this 'widget designer' in the settings. The post doesn't specify how to associate this designer with an existing widget created by the module builder in the front end of Sitefinity. 
  5. John Oct 24, 2013
    NM, it worked, it just took a while to refresh I suppose

    Leave a comment