Try Now
More in this section

Forums / Developing with Sitefinity / How to filter content by multiple tags?

How to filter content by multiple tags?

2 posts, 0 answered
  1. Keith
    Keith avatar
    67 posts
    13 Sep 2010
    07 May 2013
    Link to this post
    I have a dynamic content type (created in module builder) that I need to be able to filter across multiple tags (ie. the user can select one or more tags on a page and a list of content will filter according to the tag(s) that they have selected.)
    What is the easiest way to accomplish this?
  2. Stanislav Velikov
    Stanislav Velikov avatar
    1113 posts
    20 Oct 2016
    10 May 2013
    Link to this post

    The categories and tags widgets render the taxonomies in tree view control or as a list of categories/tags. The thing with selecting and filtering for multiple categories and tags is that the built in control allows single selection of an item in the tree/list. It does not save a set of selected categories based on which a query can be made to find all news items that have all selected categories.

    To have this functionality a custom control have to be created (for example a list for multiple selection) utilizing the taxonomies API to render a list of all categories/tags and allow selection of a set of taxons based on which a query to be executed and filter the list of content items.

    After this you can either create your own control to display the dynamic items (with repeater for example), or create a custom DynamicContentViewMaster class (it is responsible for displaying the list of dynamic items). Then override the InitializeControls method of the class like so:

    protected override void InitializeControls(Telerik.Sitefinity.Web.UI.GenericContainer container)
                int? totalCount = 0;
                this.DynamicContentListView.DataSource = GetMatchedResult(tagsCollection);
                this.DynamicContentListView.ItemDataBound += new EventHandler<RadListViewItemEventArgs>(this.DynamicContentListView_ItemDataBound);
                if (this.EnableSocialSharing == true)

    where tagsCollection are the selected from the list control tags placed in an array. Here is the sample GetMatchedResult() method:
    public List<DynamicContent> GetMatchedResult(string[] taxonomies)
                var providerName = String.Empty;
                DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager(providerName);
                Type testType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.ModuleTest.Test");
                var matchedData = new List<DynamicContent>();          
                var dynamicItemsAll = dynamicModuleManager.GetDataItems(testType).Where(i=>i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live);
                var number = taxonomies.Count();
                foreach (DynamicContent itm in dynamicItemsAll)
                    int counter = 0;
                    for (int i = 0; i < number; i++)
                        var tagsDesc = TypeDescriptor.GetProperties(itm).Find("Tags", true);
                        if (tagsDesc != null)
                            // need to implement a check if tagsDesc contains taxonomies[i] and if so increment the counter
                    if (counter == number)
                return matchedData;
    Now in order to be able to use the customDynamicContentViewMaster class you need to also override the DynamicContentView control (the whole widget) and register your custom control in its initialization. I have attached 2 custom files to this reply. Please place them in your solution and Build. Then register the CustomDynamicContentView as a custom control in the toolboxes (easiest way is to use Thunder for this). Now when you drop the custom control it will be the same as the default one (created by the module builder) but it will use the CustomDynamicContentViewMaster class.

    All the best,
    Stanislav Velikov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
2 posts, 0 answered