Copied to clipboard

Flag this post as spam?

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


  • Matty 34 posts 148 karma points
    Jul 18, 2018 @ 23:46
    Matty
    0

    Getting a Node Slug

    Hi community,

    I feel like this is a silly question but I can't figure out the way to get just the slug for a node. Is there even a built in way to do this? Currently I am using the following which seems less than bulletproof:

    @node.Name.ToLower().Replace(" ","-").Replace("&","")
    

    If the case calls for it I might change the Replace call to a Regex Replace to catch more. The only other alternative I can think of is getting the node's URL, splitting on '/' and grabbing the last element.

    Is there a way to get the just a node's slug in umbraco?

  • August 7 posts 117 karma points
    Jul 19, 2018 @ 01:12
    August
    100

    Use

    @node.UrlName
    
  • Matty 34 posts 148 karma points
    Aug 02, 2018 @ 00:22
    Matty
    0

    That's exactly what I needed! For the life of me I couldn't find that method call. Thanks for the info!

Please Sign in or register to post replies

Write your reply to:

Draft