This project is read-only.

Alter / Override Routable

Topics: Writing modules
Dec 15, 2011 at 1:34 PM


What I'm trying to do is to make it easier to handle a large hierarchy of pages, and especially to control and help with the input of Urls.

So far, I've managed to build a tree representing all the pages of my site. What I'd like to do is to somehow alter the way the RoutablePart is displayed (on the create/edit page):

- keep the textbox where you can input a url
- have a treeview below where you can click each node (parent or end) to append the url to the permalink
(eg. I click on node aa->bb->cc, that gets copied in the textbox - /aa/bb/cc/, and the user can add a page by just adding the last part "dd" for instance, without the possibility to change the beginning) 

I figured I could the change the Routable views and drivers & so on, but as it's in the Core, I really don't want to do that and I do suspect there might be an elegant solution to my problem... 

Could someone give me some pointers ? 

I've seen another discussion ( which ends up on that link ( but I'm not quite sure if it's relevant, and if it is, how to use it ...

Thanks for your help !

Dec 15, 2011 at 6:20 PM

You'll want to look at the autoroute feature that is being built for Orchard 1.4.

Dec 15, 2011 at 6:40 PM

I've actually already got a module that allows you to create hierarchical Urls. It's in the "Plumbing" feature of Mechanics. The current gallery version is slightly unreliable; there is a better version in my codeplex repository, but there's an even better version on the way that will integrate with the upcoming Alias module (which is what Autoroute sits on top of) and/or Autoroute itself.

Basically, Alias will make is easy to assign any custom Url to a content item (or to any set of route values, for that matter). Autoroute allows you to create templated Urls from tokens.

Properly recursive hierarchical menus are tricky. Autoroute will enable this in a limited fashion; you can use the Container's url as a token, but this breaks down slightly if your item doesn't have a container, i.e. it's a root level item. You also need a way to define the hierarchy. The Plumbing module attacks both of these problems, using Mechanics connectors to define a hierarchy (this technically means you can have pages on multiple Urls because the connections are many-to-many; this sounds excessive there are situations where it's useful). It has its own recursive url building, so you can have nested urls of as many levels as you like. So I'm still not quite sure the best or most useful way to use Autoroute with it.

A "treeview" UI for editing relationships will also be on the cards but not quite yet :)

Dec 16, 2011 at 12:38 PM
Edited Dec 16, 2011 at 12:43 PM

Ok, unfortunately, I can't wait until the next version of Orchard is complete... Let me rephrase my initial question:

How should I proceed if I want to change the behaviour and display of the Routable part ? Could I somehow override it ?

Actually, one of the goals behind this would be to create a widget that would generate an automatic menu (for sublevels). Based on the current Url and tree it could draw a menu (in an aside zone for instance) with a hierarchy of the pages available. But First, I need a way to add some control over the way users input pages' urls as well as provide an easy way to do so. The whole treeview thingy doesn't seem too complicated, it's more about its integration within the existing parts that I'm worried about. I really wouldn't want to risk modifying the Core code ... 

Dec 16, 2011 at 3:16 PM

You can easily override most existing code using the OrchardSuppressDependency attribute. However, replacing the routable behaviour is currently very complicated, let alone the complexities of a tree structure (which isn't really as simple as you think); which is why I've gone to some lengths to do this already in my own module, and why there will be core features in the next version to make this much easier.

Your two easiest options are:

a) Use the upcoming version now (it's available in the source repository, and it works, you don't have to wait for the release)

b) Use my Plumbing module

Otherwise, it's a very complicated task, and too big for me to write any kind of how-to, although if you had more specific questions about parts of the task I could try to help.

Dec 20, 2011 at 12:37 PM
Ok I'll try to look at the current source code. Could you give me the
url of the fork to check out? As well as what I should be looking for?
Dec 20, 2011 at 12:54 PM

It depends which option you want to use. You can try out the Autoroute fork, I give some details about that in this thread:

Or, if you just want to generate your own paths and use Alias, use the 1.x branch from the normal Orchard repository, and additionally install the alias module:

You should probably get the Autoroute fork anyway because there you can see some examples of IAliasService being called to set an Alias for a set of routevalues.

If you want to look at Plumbing the code is at:

The most recent branches are semi-working and need Alias, but there are some problems which I'm working on right now. Or you could fall back to the "1.2 compatible" or "1.3 compatible" branches which are prior to the big changes and were reasonably stable.