This project is read-only.

Autoroute - User hints for custom route / lock to folder?

Topics: Customizing Orchard, Writing modules
Oct 28, 2014 at 3:23 PM
Custom Autoroute Routes
I'm setting up the autoroute within a module on a content type like this:
.WithSetting("AutorouteSettings.PatternDefinitions", "[{Name:'Example Page Url', Pattern: 'profiles/{Content.Fields.ExamplePart.ExampleUrl}', Description: '/profiles/(profilename)'}]")
What I wanted to do was have the user be able to customise their (profilename) part of the url but have it locked under /profiles/ but this doesn't seem to possible.

The UI loads up with a label prefix of and then the textbox is empty.

Ideally I want the prefix to be locked to [textbox]

So that the autoroute system can just validate and manage the custom url for it.

If I set allow custom routes to false then it doesn't let me enter anything in. If I set it true then it lets me change the entire url. Is there a middle ground?
Oct 30, 2014 at 6:35 AM
AutoRoute doesn't support this as you've seen, but it's an interesting idea. At this you will have to implement your own routing part and use that instead of AutoroutePart. If you do, I'd be interested in seeing a demo during one of our weekly meetings.
Oct 30, 2014 at 5:45 PM
I don't understand, are you saying using a text field to enter the profilename and using it in the route template doesn't work ?
Oct 30, 2014 at 6:12 PM
No it works but as the admin users of the website will be making their own pages using my module I want the autoroute module to lock them all in, for example, a /profiles/ subfolder.

I can set that up like Pattern: 'profiles/{Content.Fields.ExamplePart.ExampleUrl}' but when the page runs it only applies this if they leave the field blank.

Simply put, sooner or later some idiot is going to create their profile page in the wrong place :)
Oct 30, 2014 at 7:07 PM
I think you can solve your problem with AutoRoute and an additional textfield (if I understand it right).
Lock the autoroute, so thats not editable for the user and set the default pattern to profiles/{Content.Fields.YourContentTypeName.YourTextFieldName}. In that case, everytime the user changed the textfield, autoroute generates the url new with the value of these textbox. Don't forget to enable the checkbox "Automatically regenerate when editing content" at the autoroute part.
Oct 31, 2014 at 12:35 PM
benschi11 wrote:
I think you can solve your problem with AutoRoute and an additional textfield.
Thanks for your help benschi11, I think this is roughly the route I will take for this project.

You actually helped me out in another thread already with some custom token code so that I could expose this additional textbox through a property on one of my Parts :)