Copied to clipboard

Flag this post as spam?

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

  • Nate 143 posts 184 karma points
    Jun 05, 2012 @ 02:03

    Writing URLs like Umbraco

    I'm moving some of my content out of Umbraco and into a database.  I want to keep the same URL structure that I currently have.

    ie: /cycling/workouts/name-of-workout

    I can do a url rewrite to get /cycling/workouts?workoutName=name-of-workout to /cycling/workouts/name-of-workout.

    What I'm looking for is a function that converts "Name of Workout" to "name-of-workout".  This is a simple case with just spaces and .toLower(), but I believe umbraco has a better internal function to do this. I'd also like to convert "name-of-workout" back to "Name of Workout" so I could query the database for the appropriate data.

    Does anyone know if there's an API to do this switch or where the function is in the source?


  • Richard Soeteman 4003 posts 12631 karma points MVP
    Jun 05, 2012 @ 07:46
    Richard Soeteman

    Why would you want to move that out, seems like a function of a CMS to me. But umbraco.library.niceUrl is in charge of generating the url's you don't have any influence about the renderung process.

  • Mike Chambers 631 posts 1227 karma points c-trib
    Jun 05, 2012 @ 11:32
    Mike Chambers

    not sure about inbuilt umbraco... but you could use ToTitleCase() from 


    string input = "name-of-workout";
    System.Globalization.TextInfo ti = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo;
    input =  ti.ToTitleCase( input.replace("-", " ") );
  • Sean Mooney 131 posts 158 karma points c-trib
    Jun 05, 2012 @ 14:27
    Sean Mooney

    Here is the native umbraco function that does it:

    umbraco.cms.helpers.url.FormatUrl("Name of Workout")

    This uses the urlReplacing section in umbracoSettings.config to replace all characters.

    However I don't believe you can reverse it. What I tend to do is have a column for Name and a column for UrlName (using the funtion above) this allows me to query by either.

  • Nate 143 posts 184 karma points
    Jun 05, 2012 @ 18:39

    Thanks Sean, that's exactly what I was looking for.

    The reason I'm moving my workouts out of Umbraco is that our site plans on letting users generate workouts.  That means 1,000s of workouts being updated regularly.  Plus I do some advanced sql queries on them to categorize/sort them.

Please Sign in or register to post replies

Write your reply to: