Anders Hattestad
May 13, 2011
  4383
(3 votes)

Mount EPiServer Community Club as part of the page structure

imageIn a intranet project I’m working on we are going to use Community for collaboration between the employees. But we needed to mix one club and other EPiServer pages together. Community out of the box gives us 1 page branch that shows all the clubs.

So what I wanted was to mount the original club structure as a Page Provider structure inside my other content.

 

 

image

I have done some work before that take on substructure and mount is it as a sub branch in my blog post:

PageProviders and DDS, a match from heaven…

The blog only got a 1 rating, but the concept is easy to use, and can be used in many different ways. Here I’m going to use that to mount the Club structure in different places.

 

So I made myself a page type AttachClubFolderPageType and if you create that page I added a EditPanel plugin that give you the option to either create a new club or attach yourself to an existing club. This page type could default be a system page, before it become a normal page when its mounted.

image

The name and intro field of the club will be this parents pagename and main intro. In this case Fagområde D.

After you have created the club you can mount the page provider. This can be done by code as shown by Alan in this blog post.  The status of the mount and the connection between the club and the mount page will be preserved in a dynamic data store table.

image

The ClubFolder page will be changed so it redirects to Home.

So far so good. But the Community templates uses a request variable clubID to show the current clubs values. So I needed to add a request parameter depending on where in the structure on was.

I first started to make my self a new Friendly URL rewriter, but discovered that there are events that one can attach to to do small stuff like this. This is create news, since its troublesome to make your own rewriter for easy stuff like this. (Thank you who ever you are that made this! Smile )

Code Snippet
  1. [EPiServer.Framework.ModuleDependency(typeof(PageTypeBuilder.Initializer))]
  2. public class AttachEvents : IInitializableModule
  3. {
  4.     #region IInitializableModule Members
  5.     public void Initialize(EPiServer.Framework.Initialization.InitializationEngine context)
  6.     {
  7.         TrackPageChanged.Current.CommentAdded += new PageEventHandler(Current_CommentAdded);
  8.         Global.UrlRewriteProvider.ConvertedToInternal += new EventHandler<EPiServer.Web.UrlRewriteEventArgs>(UrlRewriteProvider_ConvertedToInternal);
  9.         ClubvsPage.MountActive();
  10.     }
  11.     void UrlRewriteProvider_ConvertedToInternal(object sender, EPiServer.Web.UrlRewriteEventArgs e)
  12.     {
  13.         var pageRef = e.Internal as PageReference;
  14.         if (pageRef != null)
  15.         {
  16.             if (!e.Url.Query.Contains("clubID") && e.Url.QueryCollection["clubID"] == null)
  17.             {
  18.                 if (!string.IsNullOrEmpty(pageRef.RemoteSite) && pageRef.RemoteSite.StartsWith("ClubID"))
  19.                 {
  20.  
  21.                     e.Url.QueryCollection.Add("clubID", pageRef.RemoteSite.Replace("ClubID", ""));
  22.  
  23.                 }
  24.             }
  25.         }
  26.     }

 

So I attached myself to ConvertedToInternal and added the clubID based on the name of the Page Provider. The I could go to home and see club 4’s club home page. But I also needed to make all links to home, wall, image etc point to my page provider page. To archive this I needed to change some of the extension methods in the Community templates like this:

Code Snippet
  1. public static Uri GetClubUri(this Club club)
  2. {
  3.     return ClubvsPage.GetClubUrl(club, Pages.Base.PageBase.ClubHomePage);
  4.     //UrlBuilder url = new UrlBuilder(Pages.Base.PageBase.ClubHomePage.LinkURL);
  5.     //url.QueryCollection.Add("clubId", club.ID.ToString());
  6.  
  7.     //if (UrlRewriteProvider.IsFurlEnabled)
  8.     //{
  9.     //    Global.UrlRewriteProvider.ConvertToExternal(url, Pages.Base.PageBase.ClubHomePage.PageLink, Encoding.UTF8);
  10.     //}
  11.  
  12.     //return url.Uri;
  13. }

So it pointed to a method that checked if this club was mounted and what page provider page it pointed to.

After that was done, all the links to this club or other part of the club pages was rerouted to my page provider pages.

Then I only needed a method to find what club (if any) a normal page was connected to.

So in user controls I wanted to use the current club I’m using this method

Code Snippet
  1. int _currentClubId = -1;
  2. public Club CurrentClub
  3. {
  4.     get
  5.     {
  6.         if (_currentClubId==-1)
  7.         {
  8.             int currentClubId = 0;
  9.             if (!int.TryParse(Request.QueryString["clubId"], out currentClubId))
  10.             {
  11.                 var tmpP=CurrentPage;
  12.                 while (tmpP != null)
  13.                 {
  14.                     if (!tmpP.PageLink.IsRemote())
  15.                     {
  16.                         currentClubId = ClubvsPage.GetClubForPage(tmpP.PageLink.ID);
  17.                         if (currentClubId > 0)
  18.                             break;
  19.                     }
  20.                     if (PageReference.IsNullOrEmpty(tmpP.ParentLink))
  21.                         break;
  22.                     tmpP = EPiServer.DataFactory.Instance.GetPage(tmpP.ParentLink);
  23.                 }
  24.             }
  25.             _currentClubId = currentClubId;
  26.         }
  27.         if (_currentClubId>0)
  28.             return ClubHandler.Instance.GetClub(_currentClubId);
  29.         return null;
  30.     }
  31. }

which basically move up to it finds the owner of the clubFolder page and returns the current club, else it returns null.

so if I’m in this location

image

I can get the members of the club and display them like this

image

 

I don’t know what happens if I mount 100+ of page providers. There could be some performance issues. But as far as I can tell I haven't experienced any of that yet. Keep my fingers crossed Smile.

The code is uploaded to the code section here

but at the moment there is an error uploading, so it’s not there yet.

May 13, 2011

Comments

Please login to comment.
Latest blogs
Opti ID overview

Opti ID allows you to log in once and switch between Optimizely products using Okta, Entra ID, or a local account. You can also manage all your use...

K Khan | Jul 26, 2024

Getting Started with Optimizely SaaS using Next.js Starter App - Extend a component - Part 3

This is the final part of our Optimizely SaaS CMS proof-of-concept (POC) blog series. In this post, we'll dive into extending a component within th...

Raghavendra Murthy | Jul 23, 2024 | Syndicated blog

Optimizely Graph – Faceting with Geta Categories

Overview As Optimizely Graph (and Content Cloud SaaS) makes its global debut, it is known that there are going to be some bugs and quirks. One of t...

Eric Markson | Jul 22, 2024 | Syndicated blog

Integration Bynder (DAM) with Optimizely

Bynder is a comprehensive digital asset management (DAM) platform that enables businesses to efficiently manage, store, organize, and share their...

Sanjay Kumar | Jul 22, 2024