Created
June 13, 2014 11:09
-
-
Save dampee/4b4fb227a86ce64e4155 to your computer and use it in GitHub Desktop.
example segment provider
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.Globalization; | |
| using System.Linq; | |
| using System.Web; | |
| using Umbraco.Core; | |
| using Umbraco.Core.Models; | |
| using Umbraco.Core.Strings; | |
| public class MyApplication : ApplicationEventHandler | |
| { | |
| protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) | |
| { | |
| base.ApplicationStarting(umbracoApplication, applicationContext); | |
| // UrlSegmentProviderResolver.Current.Clear(); | |
| UrlSegmentProviderResolver.Current.InsertType<ImmoUrlSegmentProvider>(0); | |
| } | |
| } | |
| /// <summary> | |
| /// Summary description for ImmoUrlSegmentProvider | |
| /// </summary> | |
| public class ImmoUrlSegmentProvider : IUrlSegmentProvider | |
| { | |
| /// <summary> | |
| /// The provider. | |
| /// </summary> | |
| private readonly IUrlSegmentProvider provider = new DefaultUrlSegmentProvider(); | |
| /// <summary> | |
| /// Gets the default url segment for a specified content. | |
| /// </summary> | |
| /// <param name="content">The content.</param> | |
| /// <returns>The url segment.</returns> | |
| public string GetUrlSegment(IContentBase content) | |
| { | |
| return this.GetUrlSegment(content, CultureInfo.CurrentCulture); | |
| } | |
| /// <summary> | |
| /// Gets the default url segment for a specified content. | |
| /// </summary> | |
| /// <param name="content">The content.</param> | |
| /// <param name="culture">The culture.</param> | |
| /// <returns>The url segment.</returns> | |
| /// <remarks>This is for when Umbraco is capable of managing more than one url | |
| /// per content, in 1-to-1 multilingual configurations. Then there would be one | |
| /// url per culture.</remarks> | |
| public string GetUrlSegment(IContentBase content, CultureInfo culture) | |
| { | |
| if (content.ContentTypeId != 1086) | |
| { | |
| return null; | |
| } | |
| var segment = this.provider.GetUrlSegment(content); | |
| // return string.Format("{0}-{1}-{2}", content.Id, segment, content.GetValue("city")); | |
| return string.Format("{0}-{1}-{2}", content.GetValue("typeDescription"), content.GetValue<string>("city"), segment).ToUrlSegment(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment