One of the new features in Orchard 1.4 is Autoroute, which like most features, arrives in the form of an Orchard Module. Autoroute is a new Content Part that attaches to Content Types and replaces the Route Part to offer much more flexibility in routing patterns for routable content types. Autoroute provides the ability to create and select custom route patterns, override patterns on a case by case basis, and the ability to regenerate the route when new versions of the content item are saved. In addition to specifying static values in the routes, Autoroute also leverages tokens in Orchard that allow you to create routes based on dynamic information such as creation date, user, and other information that may vary from content item to content item.
With the release of Orchard 1.4 we can say goodbye to the Route Part. The Route Part actually had a tough life as it was pulling double-duty for routable content types. It was both handling the title of the Content Type as well as the routable slug. Just after you typed in a title for a page or blog post, for example, it was the Route Part that generated a unique slug for that content item based on the title. Since it only generated the slug based on the title it wasn't possible to generate slugs based on more custom patterns and dynamic information like creation date, user, etc. The Route Part also had this nasty side-effect that caused a Publish Event to fire whenever it obtained a new slug for the content item, causing the Rules Engine in Orchard to be of very little use when dealing with the publishing of content types. Autoroute fixes these limitation and problems, which is a great thing!
In Orchard 1.4 you will now see the Route Content Part replaced by the Autoroute and Title Parts. The Autoroute Part will handle the route generation needs for the content item and the Title Part will handle the Title needs. Hence, in Orchard 1.4 you will see the Autoroute and Title Parts attached to a content type as opposed to the Route Part.
Whereas the Route Part in Orchard had no settings, the Autoroute Part has essentially 3 settings.
An example of these settings are shown below for a Blog Post.
Three things you will notice.
If you have the proper authorization, you can change these settings by editing the Autoroute Part of the Blog Post Content Type.
If you don't like the default Autoroute Pattern for a blog post, change it. Let's go token crazy and specify a new route based on the Blog, Date Created, and Title of the blog post in Orchard. Here is the new pattern for the blog post route.
You probably recognize this old school blog post pattern as it will generate a route like this:
Specify this as the default pattern for each blog post.
When the blog post contributor goes to create a new blog post they are able to see the default pattern as a hint, but also have the ability to override it since I left the Allow custom patterns option selected.
One thing you should note is that when the Allow custom patterns in the Autoroute Settings is not selected, there is no textbox allowing the contributor to type in a custom route. The Orchard Blog Post Route will only be generated by Autoroute.
When I type in a new title for this Blog Post and save it, Autoroute will generate a new route based on my default pattern.
One of the Autoroute Settings mentioned earlier is the ability for Autoroute to regenerate the route after a user edits the content item. This is an interesting option as that it is probably a neat idea before an item is published for the first time, but perhaps not so good for SEO once an item has been published. Having the route change for an item that has already been indexed in various search engines and linked by 3rd parties is not the best of ideas, but I am sure there are reasons for it beyond SEO.
Let's say we have saved a blog post using the custom Autoroute pattern for Orchard Blog Posts mentioned earlier. This pattern is based on the blog post's title, which in this case was called Original Title ( catchy I know ). I originally created this blog post on February 23, 2012 with a title of Original Title and you can see the current route as blog/02/23/2012/original-title.
I am making a change to the title of this blog post and calling it, Route Will Change With New Title.
If I have selected the Autoroute option to automatically regenerate when editing content for blog posts, once I re-save the blog post the route for this blog post will be regenerated based on the new blog post title which is part of the default routing pattern. Now that I have changed the title and saved it, notice the new permalink for the Orchard Blog Post.
The new Autoroute Part in Orchard 1.4 is a great new content part and along with the Title Part replaces the Route Part in Orchard. It not only offers the ability to allow custom patterns and regenerate routes after editing a content item, but it also provides a feature rich pattern mechanism based on additional tokens other then the content item's title. Orchard administrators have the ability to modify Autoroute Settings as well as specify new and default patterns for route generation. Along with the new Alias Feature, which I will talk about in a future post, routable content types in Orchard just got a whole lot more interesting.
Check out my other Orchard Tutorials.