Copied to clipboard

Flag this post as spam?

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


  • David F. Hill 122 posts 242 karma points
    Jan 05, 2014 @ 20:49
    David F. Hill
    0

    Derive the urlName before a node is published

    Hello Umbraco colleagues,

    (Umbraco ver 6.1.6)

    I'm trying to create a string that would be the same as the urlName for a published node - only I need it before the node has been published.
    I'm need this string in a custom publishing event handler so, at that point, the urlName property hasn't been determined.

    Seems like there would be a method I could call where I can pass to it the name of the node that's about to be published and it would return the "calculated" urlName. I've tried to find the code that Umbraco uses (when a node is published) to determine the urlName from the Name property - - but I haven't found it yet.

    Any suggestions?

    Thanks,
    David Hill

  • Andreas Kaltenhuber 107 posts 286 karma points
    Sep 22, 2014 @ 12:04
    Andreas Kaltenhuber
    0

    Hi,

    did you find the method for this? Looking at the same "problem" at the moment.

    thx,

    andreas

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Sep 22, 2014 @ 17:51
    Jeroen Breuer
    0

    Hello,

    There is an extension method you can use for this. It's in the Umbraco.Core namespace. After adding that namespace you can do .ToUrlSegment() on any string. If you use that method on the name of the node you'll get the correct value. In newer versions of Umbraco there is also the UrlName property on a node.

    Jeroen

  • David F. Hill 122 posts 242 karma points
    Sep 23, 2014 @ 00:18
    David F. Hill
    0

    Thanks for the information, Jeroen. Even though it has been months since I posted the question, it's very helpful.

    Cheers! David

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Sep 23, 2014 @ 09:15
    Jeroen Breuer
    0

    Glad I could help. If it's the answer you were looking for please mark it as the solution.

    Jeroen

  • Andreas Kaltenhuber 107 posts 286 karma points
    Sep 23, 2014 @ 10:24
    Andreas Kaltenhuber
    0

    Thanks Jeroen for the hint, definitely have to look at the umbraco.core classes in more detail ;-)

    Another question regarding umbracoUrlAlias in using in an publishing event: What i'm going to try is, to set the umbracoUrlAlias to the same value as the urlName but that value is for sure not available on IContent. node.Name.ToUrlSegment() works but it's not safe to be a unique url if there are others with the same node.Name.

    Is there an easy way to use some umbraco method to get the UrlSegment unique, or do i have to implement my own?

    thx a lot

    Andreas

Please Sign in or register to post replies

Write your reply to:

Draft