Umbraco CMS Vorto: Create Friendly url's


Here's my solution to create translated url's:

Start with a property on your page, called "pagename" which is a Vorto TextString. This field will be the alternative for the nodename, which can't be translated. If the translated field is empty, my code will use the nodename as fallback.

The url's will look like this: mysite.com/en/my-page/subpage. You'll see the language part contains 2 characters and is in my case just the first 2 characters from the culturename. Feel free to change this if your case needs something else.

You can download my code on http://progressive.be/vortoUrl.zip

The code consist of the following files:

VortoContentFinder: This is the contentfinder which will look up the URL and will split it into parts and tries to find the corresponding node.

Events.cs: This file registers the VortoContentFinder. It's necessary to use this.

ExtensionsForString: Contains an extensionmethod to clean the vorto Pagename values, to have it url friendly

ExtensionsForIPublishedContent: This contains 2 important extensionmethods: VortoUrl(): This will give you the translated url you can use in your pages and menu's. Use it instead of the default Url property on iPublishedContent. The other extensionmethod is PageName(): When you create a menu, use PageName instead of the Name property. This will give you the translated pagename or default nodename as fallback

Usage in your view: As example; i'll give you my menu code:

            @foreach (var menu in menuItems)
            {
                <li><a href="@menu.VortoUrl()"><span>@menu.PageName()</span></a></li>
            }