Last active
September 10, 2015 11:50
-
-
Save komainu85/3a6efad20ab1b2a56385 to your computer and use it in GitHub Desktop.
Sitecore Friendly URL Computed Field
This file contains 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.Xml; | |
using Sitecore.ContentSearch; | |
using Sitecore.ContentSearch.ComputedFields; | |
using Sitecore.Data.Items; | |
using Sitecore.Links; | |
using Sitecore.Xml; | |
namespace MikeRobbins.ContentSearch.ComputedFields | |
{ | |
public class FriendlyUrl : AbstractComputedIndexField | |
{ | |
public override object ComputeFieldValue(IIndexable indexable) | |
{ | |
var scIndexable = indexable as SitecoreIndexableItem; | |
if (scIndexable != null) | |
{ | |
var item = (Item)scIndexable; | |
if (item != null) | |
{ | |
var opts = LinkManager.GetDefaultUrlOptions(); | |
opts.Site = Sitecore.Sites.SiteContext.GetSite(SiteName); | |
return LinkManager.GetItemUrl(item, opts); | |
} | |
} | |
return null; | |
} | |
public FriendlyUrl() | |
{ | |
} | |
public FriendlyUrl(XmlNode configurationNode) : this() | |
{ | |
SiteName = XmlUtil.GetAttribute("siteName", configurationNode); | |
} | |
public string SiteName { get; set; } | |
} | |
} |
This file contains 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
<fields hint="raw:AddComputedIndexField"> | |
<field fieldName="urllink" siteName="SiteName">MikeRobbins.ContentSearch.ComputedFields.FriendlyUrl,MikeRobbins.ContentSearch</field> | |
</fields> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment