Question

I have a Sitecore 7.1 site and I'm trying to figure out what the best way to implement a tag search for a blog is.

Ideally I would like to have a URL like this: /tags/tag-goes-here

There should be an item sitecore/content/home/tags in my content tree so I can edit the content etc using Sitecore. I would want all routes like the above to be mapped to the item and be able to get the "tag-goes-here" parameter into my controller/rendering somehow.

I've tried to use routes but I'm not sure if this is the right approach. It maps to a simple controller but I might be on the wrong track. I've added the following route for this:

routes.MapRoute(
            "Tags",
            "tags/{tag}",
          new
          {
              controller = "Tag", 
              action = "Index", 
              tag = UrlParameter.Optional, 
          });

It works but does not quite do what I want. It just renders my view in the browser but I can't use Sitecore to add any renderings or content to it as there is no matching item in Sitecore. What would be the best way to approach this in Sitecore MVC?

Thanks.

Was it helpful?

Solution

By specifying the route as you are and specifying the controller you are in effect bypassing Sitecore. See section 4.1 of the Sitecore MVC Developers Guide

You could use Wildcard Items (section 1.2.6 of Reusing and Sharing Data document) to handle the tags, this would allow you to deal with the Item like any other Sitecore Item and add layout/rendering/rules etc.

You can find some relevant examples here: Sitecore MVC Music Store, it's a Sitecore 6.6 example but the concepts are the same still.

You could also take a look at the Wildcard Module but looking at the source code I'm not sure it will work with MVC since there is some WebForms specific code but it should be easy enough to modify.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top