Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidVeksler/89b7f5a3e3c04cd37b62 to your computer and use it in GitHub Desktop.
Save DavidVeksler/89b7f5a3e3c04cd37b62 to your computer and use it in GitHub Desktop.
Update for Umbraco 7
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Persistence.Querying;
using Umbraco.Web.Routing;
namespace FEE.Domain.MemberProfile
{
// From http://creativewebspecialist.co.uk/2013/12/03/using-umbraco-pipeline-for-member-profile-urls/
public class MemberProfileContentFinder : IContentFinder
{
public bool TryFindContent(PublishedContentRequest contentRequest)
{
var urlParts = contentRequest.Uri.GetAbsolutePathDecoded()
.Split(new[] {'/'}, StringSplitOptions.RemoveEmptyEntries);
//Check if the Url Parts
// Starts with /profile/*
if (urlParts.Length > 1 && urlParts[0].ToLower() == "profile")
{
//Lets try & find the member
var memberName = urlParts[1];
//Try and find a member where the property matches the memberName
List<IMember> tryFindMember =
ApplicationContext.Current.Services.MemberService.GetMembersByPropertyValue("umbracoUrlName",
memberName).ToList();
if (!tryFindMember.Any()) // try a partial match just in case
{
tryFindMember = ApplicationContext.Current.Services.MemberService.GetMembersByPropertyValue("umbracoUrlName",
memberName,StringPropertyMatchType.Contains).ToList();
}
//See if tryFindMember is not null
if (tryFindMember.Any())
{
//Need to set the member ID or pass member object to published content
HttpContext.Current.Items["memberProfile"] = tryFindMember.FirstOrDefault();
//Set the Published Content Node to be the /Profile node - can get properties off it & my member profile in the view
contentRequest.PublishedContent =
contentRequest.RoutingContext.UmbracoContext.ContentCache.GetByRoute("/people/member-profile");
}
//Return true to say found something & stop pipeline & other contentFinder's from running
return true;
}
//Not found any content node to display/match - so run next ContentFinder in Pipeline
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment