Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nikki Strømsnes 16 posts 58 karma points
    Jun 10, 2016 @ 08:59
    Nikki Strømsnes
    0

    Dynamically rewrite URL (stripping certain document types from the URL)

    Hello friends!

    I am developing a site, where I'm trying to separate content nodes from page nodes, if that makes sense. It looks very structured and neat in the back office but the unfortunate side effect is that it creates rather complicated URLs. For example, a structure may look like this:

    Home
    - Calendar
    -- Modules
    --- Intro text
    --- Calendar List
    ---- My awesome event
    

    In this case the "Modules" is just a folder, which contains content for the "Calendar" page. "Calendar list" is simply a node, which outputs children it has in a list view.

    That's very awesome, but if I want to read about "My awesome event", the link will be: "/calendar/modules/calendar-list/my-awesome-event/", which is no bueño. I'd like it to simply be "/calendar/my-awesome-event".

    I am aware, that I can manually set an umbracoUrlAlias for each page, but I want it to happen magically, so the content manager doesn't have to think about it.

    So my question is as follows:

    Is it possible to set up some rules, that automatically strips that node name from the URL?

    Can I somehow enter logic into the property for the node? What I mean, is that I set a umbracoUrlAlias, where the default value is "/calendar/@Url". (Silly question, I assume answer is "no").

    Alternatively, I could organize all my calendar items in the root, and somehow reference them in a macro on the "actual" page. But then I'd still need to figure out a way to rewrite the URL for each item.

    I should note, that I'm not a backend development prodigy, so I'd like to steer away from a very complex backend solution. In that case, I'll simply suck it up and output it directly under the "Calendar" node.

  • Dennis Adolfi 1082 posts 6446 karma points MVP 5x c-trib
    Jun 10, 2016 @ 09:31
    Dennis Adolfi
    0

    Hi Nikki!!

    The way i usally organize it is quite similar to your approuach, except i make a general rule of not making it possible to create nodes with templates in my "Modules" folder. I.e the "Modules" as simply components of a page, and does not contain other pages. You mentioned this aswell when you wrote:

    Alternatively, I could organize all my calendar items in the root, and somehow reference them in a macro on the "actual" page. But then I'd still need to figure out a way to rewrite the URL for each item.

    Except i usally dont do a macro, except I do a Module called something like "Event-listing" which generally dont have any properties, its just a way of telling the UI where among my modules i like to render the events.

    So the structure would look something like this:

    Home
    - Calendar
    -- Modules
    --- Intro text
    --- Event-List <-- Listing module
    --- Calendar List
    -- My awesome event <-- Event page
    -- My other awesome event <-- Event page
    

    This way, the events URL will be /Calendar/My-awsome-event. And it´s also quite handy when I´m intrested in a view, how many events the calender has, i can just check @calender.Children(), where as in the structure you wrote, whould make that tricker. (Well, not super tricky, but you get what i mean).

    I dont think you can solve this whitout doing some backend coding, I quess you could create a Custom UrlProvider to help you fix this. If you want, i can look in to it for you?

    Im not saying my way is the correct way, i just thought I share my point of view and how I usally organize a similar scenario.

    All the best / Dennis

  • Nikki Strømsnes 16 posts 58 karma points
    Jun 10, 2016 @ 10:02
    Nikki Strømsnes
    0

    Thanks for chiming it!

    Yep. That makes perfect sense, and that's my alternate solution. My only gripe with it, is if I have a lot of past and future events, or a news list, it will create a lot of nodes in the tree structure. That is why I wanted to create a separate node to keep them (in a list view, to reduce the number of nodes in the tree view).

    I think I'm going to solve it as you propose.

  • Dennis Adolfi 1082 posts 6446 karma points MVP 5x c-trib
    Jun 10, 2016 @ 10:06
    Dennis Adolfi
    0

    I get that Nikki. A solution for avoiding the massive tree view could be to use the "Enable List View"?

  • Sotiris Filippidis 286 posts 1501 karma points
    Jun 10, 2016 @ 09:56
    Sotiris Filippidis
    0

    I used to have the same problem, and I created a package for this purpose. Have a look at VirtualNodes which allows you to specify document types that are completely excluded from Umbraco-generated URLs. This is not an alias, it's the actual Umbraco URL for any page.

    This will only work if the sections you need to exclude have their own doctype though.

    This package is, essentially, a specific implementation of a custom UrlProvider.

    I've set up the same UrlProvider as a separate package, in case you need to use it in a more generic way or extend it, under the name "Omit Segments Url Provider" (a.k.a. Url Sniper). This works with doctype "pairs", i.e. parent doctype - childdoctype, hiding the child doctype part from the URL whenever it finds it under the specified parent doctype.

    I hope one of those two helps!

  • Dennis Adolfi 1082 posts 6446 karma points MVP 5x c-trib
    Jun 10, 2016 @ 10:00
    Dennis Adolfi
    0

    Sotiris, that sounds like a great package. I will defenetly try it out sometime soon! Awesome!! :)

  • Sotiris Filippidis 286 posts 1501 karma points
    Jun 10, 2016 @ 10:03
    Sotiris Filippidis
    1

    Very glad to hear that! Please do, I'd appreciate some feedback!

  • Nikki Strømsnes 16 posts 58 karma points
    Jun 10, 2016 @ 10:19
    Nikki Strømsnes
    1

    Wow, that looks really awesome – it's exactly what I need! I will try it later, and report back.

    Cheers!

Please Sign in or register to post replies

Write your reply to:

Draft