Try our conversational search powered by Generative AI!

Anders Hattestad
May 13, 2011
(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.




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.


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.


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.                 {
  21.                     e.Url.QueryCollection.Add("clubID", pageRef.RemoteSite.Replace("ClubID", ""));
  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());
  7.     //if (UrlRewriteProvider.IsFurlEnabled)
  8.     //{
  9.     //    Global.UrlRewriteProvider.ConvertToExternal(url, Pages.Base.PageBase.ClubHomePage.PageLink, Encoding.UTF8);
  10.     //}
  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


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



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


Please login to comment.
Latest blogs
Headless forms reloaded (beta)

Forms is used on the vast majority of CMS installations. But using Forms in a headless setup is a bit of pain since the rendering pipeline is based...

MartinOttosen | Mar 1, 2024

Uploading blobs to Optimizely DXP via PowerShell

We had a client moving from an On-Prem v11 Optimizely instance to DXP v12 and we had a lot of blobs (over 40 GB) needing uploading to DXP as a part...

Nick Hamlin | Mar 1, 2024 | Syndicated blog

DbLocalizationProvider v8.0 Released

I’m pleased to announce that Localization Provider v8.0 is finally out.

valdis | Feb 28, 2024 | Syndicated blog

Epinova DXP deployment extension – With Octopus deploy

Example how you can use Epinova DXP deployment extension in Octopus deployment.

Ove Lartelius | Feb 28, 2024 | Syndicated blog

Identify Azure web app instance id's for an Optimizely CMS site

When running Optimizely CMS in Azure, you will be using an instance bound cloud license. What instances are counted, and how can you check them? Le...

Tomas Hensrud Gulla | Feb 27, 2024 | Syndicated blog

Introducing Image Transformer - AI Assistant for Optimizely

We've got something super cool to share with you, and it's all about giving your images a fresh spin. Image Transformer, the latest feature from ou...

Luc Gosso (MVP) | Feb 26, 2024 | Syndicated blog