The main question is: is it possible to exclude a node from the URL?
For example, we have the following Node structure:
Parent (/parent)
Child (/parent/child)
Subchild (/parent/child/subchild)
Would it be possible to exclude 'Parent' from the URL of Child and Subchild? So the URLs would be '/child' and '/child/subchild' respectively?
We've already written an IUrlProvider implementation which fixes the 'Link to document' in the back-office and NiceUrl value, but how do we use 'PublishedContentRequest.Prepared' for example to load the correct Node?
Ps. We've used this blogpost for information on the subject.
In order to be as generic as possible, let's say you want to remove any part of a url. Say the default url would be "/about-us/our-people/j/john-doe" but you want to hide the "j" in that url because it's just a folder used to arrange your people (you have a lot of them).
First, you need to write a IUrlProvider which will remove that "j" and return "/about-us/our-people/john-doe" -- looks like you've done that part already.
Second, you need a way to map that url back to a proper node. PublishedContentRequest.Prepared comes too late in the pipeline, because that event triggers once the request has been prepared, ie we have identified a node to render, a template, a rendering engine, etc. What you want is to tell the pipeline how to find a content, using that url. Do do this you need to implement and register an IContentFinder implementation.
Have a look at Umbraco.Web.Routing.ContentFinderByNiceUrl or ContentFinderByUrlAlias. You'll probably need to identify a root node, and then run an XPath query under that node. That query should return the proper content, which your finder will then assign to the request. Should not be too complex. Let me know.
The drawback here is that the IUrlProvider and the IContentFinder will process everything each time they are invoked, unless you implement your own cache. So there would be a perf hit. With default, standard urls, we cache the id-to-url (and url-to-id) so they're only computed once (as long as no content changes). Might be interesting to see how we could extend that cache so ppl can feed it with whatever they want...
Exclude a node from URL
The main question is: is it possible to exclude a node from the URL?
For example, we have the following Node structure:
Would it be possible to exclude 'Parent' from the URL of Child and Subchild? So the URLs would be '/child' and '/child/subchild' respectively?
We've already written an IUrlProvider implementation which fixes the 'Link to document' in the back-office and NiceUrl value, but how do we use 'PublishedContentRequest.Prepared' for example to load the correct Node?
Ps. We've used this blogpost for information on the subject.
In order to be as generic as possible, let's say you want to remove any part of a url. Say the default url would be "/about-us/our-people/j/john-doe" but you want to hide the "j" in that url because it's just a folder used to arrange your people (you have a lot of them).
First, you need to write a IUrlProvider which will remove that "j" and return "/about-us/our-people/john-doe" -- looks like you've done that part already.
Second, you need a way to map that url back to a proper node. PublishedContentRequest.Prepared comes too late in the pipeline, because that event triggers once the request has been prepared, ie we have identified a node to render, a template, a rendering engine, etc. What you want is to tell the pipeline how to find a content, using that url. Do do this you need to implement and register an IContentFinder implementation.
Have a look at Umbraco.Web.Routing.ContentFinderByNiceUrl or ContentFinderByUrlAlias. You'll probably need to identify a root node, and then run an XPath query under that node. That query should return the proper content, which your finder will then assign to the request. Should not be too complex. Let me know.
The drawback here is that the IUrlProvider and the IContentFinder will process everything each time they are invoked, unless you implement your own cache. So there would be a perf hit. With default, standard urls, we cache the id-to-url (and url-to-id) so they're only computed once (as long as no content changes). Might be interesting to see how we could extend that cache so ppl can feed it with whatever they want...
is working on a reply...