Copied to clipboard

Flag this post as spam?

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


  • MB 113 posts 422 karma points
    Jan 11, 2021 @ 04:53
    MB
    0

    API to generate URL-Slug from Node-Name

    For various reasons, I need to save the URL-Slug for a new node, as the node is being saved, in a separate area, and need to ensure the same rules are applied for sanitizing it, so that it exactly matches the URL-Slug generated by Umbraco when saving the node.

    I assume there is a callable API function to process the node-name to a URL-Slug - i.e. the Umbraco 'Slugify' utility - but finding it is another story.

    Anyone?

  • Marc Goodson 2157 posts 14411 karma points MVP 9x c-trib
    Jan 11, 2021 @ 08:34
    Marc Goodson
    101

    Hi MB

    There is an Extension method called ToUrlSegment()

    https://github.com/umbraco/Umbraco-CMS/blob/v7/7.15.4/src/Umbraco.Core/StringExtensions.cs#L1222

    In the Umbraco.Core namespace

    So if you have the string representation of the name of the node that you are creating, the url slug should be just the result of calling ToUrlSegment() on it

    regards

    marc

  • MB 113 posts 422 karma points
    Jan 11, 2021 @ 08:54
    MB
    0

    Excellent - exactly what I needed.

    I read the code, and it has it's own way of handling UTF8 - finding definitive rules on this and diacritic handling is a real can of worms - but so long as I'm doing it the 'Umbraco' way, that's all that matters to me.

    Cheers.

Please Sign in or register to post replies

Write your reply to:

Draft