Advanced route hijacking on similar document type names
How can we extend the route hijacking to add routes for similar document type names.
For example, if we have the following document types
NewsList1
NewsList2
NewsList3
we would like all of them to route to the controller NewsListController (which extends RenderMvcController or a custom implementation of it).
Is there a way to route these document types to the controller without creating separate controllers for each unique doc type alias? We have similar doc types created multiple times to allow for minor UI differences, but the base functionality is the same.
Can we add our own custom routes to Umbraco's hijacked routing table? If so, how would this be accomplished?
Yes, we're aware of that and are using that for other functionality, but we were hoping there'd be a way to add our own custom routes to the hijacked routing table.
Do you know if that's possible? We'd like to 1) query the doc types on app start, 2) find the "similar doc types" then 3) register them as hijacked routes.
1 and 2 are very easy but we can't figure out how to do 3.
There may be a better way (e.g., overload however Umbraco is finding the controller by doctype), but you should be able to at least create your own route using a catch-all expression and a custom route constraint that matches the doctype based on a regular expression. If you want to look for a more elegant way, here is some Umbraco source code you'll want to look into:
Advanced route hijacking on similar document type names
How can we extend the route hijacking to add routes for similar document type names.
For example, if we have the following document types
we would like all of them to route to the controller NewsListController (which extends RenderMvcController or a custom implementation of it).
Is there a way to route these document types to the controller without creating separate controllers for each unique doc type alias? We have similar doc types created multiple times to allow for minor UI differences, but the base functionality is the same.
Can we add our own custom routes to Umbraco's hijacked routing table? If so, how would this be accomplished?
Any advice or direction would be helpful.
bump
You can set a defaultcontroller for route hijacking.
So all doctypes will use that controller. You still can have controllers for specific doctypes.
https://our.umbraco.org/documentation/Reference/Templating/Mvc/custom-controllers#Changethedefaultcontroller
Dave
Yes, we're aware of that and are using that for other functionality, but we were hoping there'd be a way to add our own custom routes to the hijacked routing table.
Do you know if that's possible? We'd like to 1) query the doc types on app start, 2) find the "similar doc types" then 3) register them as hijacked routes.
1 and 2 are very easy but we can't figure out how to do 3.
I think the easiest way to do this would be
To create controllers for each of your doctypes and inherit them from one base controller
Dave
There may be a better way (e.g., overload however Umbraco is finding the controller by doctype), but you should be able to at least create your own route using a catch-all expression and a custom route constraint that matches the doctype based on a regular expression. If you want to look for a more elegant way, here is some Umbraco source code you'll want to look into:
Thanks a lot Nicholas.
This is more what we were looking for. We'll give it a shot and post our results back here.
is working on a reply...