Removing Appended Query Strings When Using Archive and Categories Widget in Sitefinity CMS

Removing Appended Query Strings When Using Archive and Categories Widget in Sitefinity CMS

April 19, 2013 0 Comments

The content you're reading is getting on in years
This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.

When filtering content items in Sitefinity CMS using both categories/tags widget and archive by query, a string gets appended to the previous query string. This blog post explores how you can remove it.

By default archive and categories/tags widgets work with UrlPath which is by default configured on each widget against with filtering can be performed: 

site.com/page/year=2013/month=04/day=02

The problem doesn`t appear when filtering using UrlPath.

When UrlPath is changed to QueryString by editing a widget, go to advanced properties->UrlEvaluationMode and set it form UrlPaht to QueryString. Here is a screenshot.

The widgets will provide the filtering functionality by appending a query string to the current page URL.

The problem comes when  both archive and categories/tags widget perform filtering together.

First, filter with the archive widget and the URL gets filtered by date: 

site.com/page?year=2013&month=04&day=02

As a next step, filter with the categories/tags widget and the category/tag filter gets appended to the archive query string:

site.com/page?year=2013&month=04&day=02&taxonomy=categories&propertyName=category&taxon=%2fproducts

This appending is used to filter based on the criteria on both the archive and the taxonomy control tough in some cases this is not needed. To overcome this, create custom archive and categories widgets that remove the already existing query string when filtering.

Attached is the source of those controls.

The logic that clears the query string is located in CustomDateEvaluator.cs for the archive control and in CustomTaxonEvaluator.cs for categories control.

case UrlEvaluationMode.QueryString:
                    var yearFullUrlKey = String.Concat(urlKeyPrefix, "year");
                    var monthFullUrlKey = String.Concat(urlKeyPrefix, "month");
                    var dayFullUrlKey = String.Concat(urlKeyPrefix, "day");
                    var qString = QueryStringBuilder.Current.Reset();

 

To install the new widgets add the attached classes in your Sitefinity project and compile it.

 Go to Administration->Settings->Advanced->Toolboxes->Toolboxes->PageControls->Sections->NavigationToolboxsection->Tools create new and in the textbox fill in the class for the new archive control.

In the case with the namespace for the classes attached: 
Control CLR Type or Virtual Path: SitefinityWebApp.CustomArchive
Controller CLR type:CustomArchive
Name:CustomArchive
Title: New Archive Control

Save changes and the new archive control is ready for use.

For categories control go to Administration->Settings->Advanced->Toolboxes->Toolboxes->PageControls->Sections->NavigationToolboxsection->Tools create new and in the textbox fill in the class for the new archive control.

In the case with the namespace for the classes attached: 
Control CLR Type or Virtual Path: SitefinityWebApp. CustomTaxonomyControl
Controller CLR type: CustomTaxonomyControl
Name: CustomTaxonomyControl
Title: New Categories Control

Save changes and the new categories/tags control is ready for use.

 

progress-logo

The Progress Guys

View all posts from The Progress Guys on the Progress blog. Connect with us about all things application development and deployment, data integration and digital business.

Comments
Comments are disabled in preview mode.
Topics
 
 
Latest Stories in
Your Inbox
Subscribe
More From Progress
d12fcc0bdb669b804e7f71198c9619a7
5 Questions Automakers Should Ask to Improve Asset Uptime
Download Whitepaper
 
SF_MQ_WCM
2018 Gartner Magic Quadrant Web Content Management (WCM)
Download Whitepaper
 
What-Serverless-Means-For-Enterprice-Apps-Kinvey
What Serverless Means for Enterprise Apps
Watch Webinar