Changing Route On Content Save

Topics: Customizing Orchard, Writing modules
Feb 26, 2013 at 2:57 AM
Hi everyone, hoping you can help.
Orchard 1.3 - no plans to upgrade for a while.

I have a content type "Course" and there are currently two different course types "classroom" and "online". The course is setup with a Title and Route part. When users enter title the route (slug?) updates to the title.

For this content I would like to override this behavior. I actually want the route to use the CourseNumber field because titles can be really long and ugly. Additionally, I want to customize the path to
www.foo.com/Courses/Distance/<CourseNumber> or
www.foo.com/Courses/Online<CourseNumber>

Is this possible (hopefully easy) in Orchard 1.3?

Thanks!
Will
Coordinator
Feb 26, 2013 at 7:22 AM
Well, you can certainly set-up your own routes. This would of course be a lot easier with Autoroute, but if upgrading is not an option...
Feb 27, 2013 at 1:41 AM
I can upgrade later. But not before the release of the currently planned set of features...
So, I'll have to figure out a way that when the admin clicks save I either overwrite the slug there or do it just after the fact.
Trying to figure out how to get access to it in the Driver for the content item but that may not be an appropriate place - if the route isn't created yet then it won't work...
Coordinator
Feb 27, 2013 at 2:04 AM
Hold on, I was talking about building a generic route that works for all the stuff in your module, not about creating a route per item. Even Autoroute doesn't work that way.
Feb 27, 2013 at 2:13 AM
Yeah, in the admin editor, when a user creates a course.
They enter a "Title" and tab to the next field. The slug auto-populates with the title - which is too long. Then the user changes it.
I need a way to override that - lock the field even.
I want that slug to always be
/courses/<DistanceOrOnline>/<CourseNumber>
/courses/distance/ethics-101

The only way I can think of would be to somehow get to the slug - after it has been created as normal the overwrite it.

Will
Coordinator
Feb 27, 2013 at 4:44 AM
You can't. You'd end up re-implementing Autoroute. It's simply not worth it. Instead, you can set-up a route from code that points to the same content item.
Feb 27, 2013 at 4:47 AM
Mind showing an example? Deadlines don't provide a lot of research time. :)

Sent from my iPhone

On Feb 26, 2013, at 11:44 PM, "BertrandLeRoy" <notifications@codeplex.com> wrote:

From: BertrandLeRoy

You can't. You'd end up re-implementing Autoroute. It's simply not worth it. Instead, you can set-up a route from code that points to the same content item.
Coordinator
Feb 27, 2013 at 5:52 AM
Look at any Routes.cs.
Feb 27, 2013 at 12:37 PM
Ok, I thought you might be referring to something else there.
Thanks Bertrand!

Sent from my iPhone

On Feb 27, 2013, at 12:56 AM, "BertrandLeRoy" <notifications@codeplex.com> wrote:

From: BertrandLeRoy

Look at any Routes.cs.