2 votes

AutoRouteTemplate

Purpose

To add Zero coding wildcard routing to Umbraco 6 and 7. Allow upto 5 extra parameters added to any existing content without writing any controllers or extra route handling. Simple out-of-the-box behavour, that is controlled by the simple inclusion of extra labels added to your existing doc type.

Why?

Have you ever wanted to turn your Search page fully SEO, from www.mysite.com/search?q=text to www.mysite.com/search/text , or create a simple member page responding to www.mysite.com/member/admin .

 

What about multiple wildcard slugs like www.mysite.com/search/text/20/30 

Usage

1.     Install package.

2.     Add a new label with an alias of ‘umbracoParam1’, 'umbracoParam2', 'umbracoParam3', 'umbracoParam4' or 'umbracoParam5', to any Document Type that you use as the basis of a page that requires routing. For example if your Search template uses a Document Type called Search, then this is where you add the new label too. The label itself is just a marker to AutoRouteTemplate, to signify that you want this template to auto route and not other templates. Which label you pick defines how many extra parameters it can handle with 'umbracoParam1' allowing one wildcard parameter

3.     In the template, use the code
    var query = this.UmbracoParam()
this will store the extra parameter/actions in the query array variable, which you can use like any other variable. If the action was never called, query will equal null.

 4. Can be used using controllers - TODO: Tell people how to do this

 

 

Spec

 

The package contains a single dll assembly that is installed in the Umbraco /bin/ folder. At initialisation every DocType within your project is examined for the existence of the umbracoParam1 alias property and using the powerful Umbraco IContentFinder class whenever a non standard request is processed, the request is checked against the valid DocTypes and the template is executed as normal with the action stored within the page session variables. this.UmbracoParam() is an extension method for HttpCurrent.Current.Items[“umbracoParam”];
Tested with Umbraco 6.1.3 & 7.1.4


Examples
Members page:
1. Create a member called 'admin'
2. Create a Document Type called ‘Member’, accept creation of matching template called 'Member'
3. Add a new label to Document Type with the alias of 'umbracoParam1'
4. In the new Template called ‘Member’, copy and paste the following Razor code:

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage

@{

       string query = this.UmbracoParam();

       var member = UmbracoContext.Application.Services.MemberService.GetByUsername(query[0]);

       if (member == null)

       {

              Response.Redirect("/error404");

       }

}

<h1>

       @member.Name

</h1>


4. Create new content based on new Member Document Type.
5. View your new content, but add /admin on the end of the URL 
    eg,
www.mysite.com/member/admin

LOG:

2.0.0

  • Have added upto 5 wildcard parameters, umbracoParam1, umbracoParam2, umbracoParam3, umbracoParam4, umbracoParam5

1.0.0

  • Init release

Screenshots

Package owner

Jonathan Richards

Jonathan Richards

Jonathan has 1723 karma points
MVP

Package Compatibility

This package is compatible with the following versions as reported by community members who have downloaded this package:
Untested or doesn't work on Umbraco Cloud
8.2.x (untested)
8.1.x (untested)
8.0.x (untested)
7.15.x (untested)
7.14.x (untested)
7.13.x (untested)
7.12.x (untested)
7.11.x (untested)
7.10.x (untested)
7.9.x (untested)
7.8.x (untested)
7.7.x (untested)
7.6.x (untested)
7.5.x (untested)
7.4.x (untested)
7.3.x (untested)
7.2.x (untested)
7.1.x (untested)
7.0.x (untested)
6.1.x (100%)
6.0.x (untested)

You must login before you can report on package compatibility.

Package Information

  • Package owner: Jonathan Richards
  • Created: 05/06/2014
  • Current version 2.0.0
  • .net Version 4.0
  • License MIT
  • Downloads: 966

External resources