Is this an awful way to filter blog posts by tag?

Topics: Customizing Orchard
Editor
Mar 19 at 5:04 PM
Our requirement is to let the user filter by tag on blog posts. We added a list of all tags to the right hand side of the page, and the user lands on the blog listing page with all entries showing.

If a user clicks on a tag, I have the URL being configured like this : http://localhost:30321/media-and-press/blog?tag=championships Then in my Summary view template for Blogs I am just choosing to render or not render the entry based on if it has the tag selected.
@{
    TagsPart tags = (TagsPart)Model.ContentItem.TagsPart;
    var selectedTagName = Request.QueryString["tag"] ?? string.Empty;
}

@if (string.IsNullOrEmpty(selectedTagName) || tags.CurrentTags.Any(x => x == selectedTagName))
{
//render blog entry
}
Obviously this stinks because it is after the query for the blogs is happening, but in order to do it the normal way of filtering by taxonomies or tags it sends them to a different page like /Tags/championship. Which is not under my layer rules, navigation, etc. Thoughts?
Coordinator
Mar 23 at 8:19 PM
Why don't you use the built-in feature that does exactly that already?
Editor
Mar 23 at 8:32 PM
It beings you to a URL that is not great. How do I keep it in the blogs section but just filter?

Sent from my Windows Phone

Coordinator
Mar 23 at 8:38 PM
What don't you like about the URL? Even if it did, why don't you point a new route that you like to the same controller action? I don't understand what you mean by "How do I keep it in the blogs section but just filter?"
Editor
Mar 23 at 9:02 PM
So, instead of it sending me to /tags/{tagname} route is there a way in my theme to override that so it goes to like /blogs/{tagname} instead?

If your blog exists at /blog then it would be ideal to be able to "filter" blogs under the same URL. For layer rule reasons, navigation logic, and SEO reasons.

Sent from my Windows Phone

Coordinator
Mar 24 at 6:22 AM
Create a new route and point it to the same action.
Editor
Mar 25 at 4:47 PM
Awesome. This worked for me. Thanks for your help here, and I now understand how to utilizes routes in the theme to extend other module functionality. For anyone wondering about this, here is my route descriptor in my theme (Routes.cs) :

new RouteDescriptor {
                Priority = 5,
                Route = new Route("media-and-press/blog/tags/{tagName}",
                    new RouteValueDictionary {
                       {"area", "Orchard.Tags"},
                        {"controller", "Home"},
                        {"action", "Search"}
                    },
                    new RouteValueDictionary(),
                    new RouteValueDictionary {
                        {"area", "Orchard.Tags"}
                    },
                    new MvcRouteHandler())
            }