A critical vulnerability was discovered in React Server Components (Next.js). Our systems remain protected but we advise to update packages to newest version. Learn More

Anders Hattestad
Jan 28, 2011
  7154
(0 votes)

PageProviders and DDS, a match from heaven…

I’m working on a pet project where I’m trying to show community entities as a tree structure in EPiServer. image But then I tried to just show on structure bellow an other page using PageProviders.

To make a PageProvider you need both a unique number inside the page provider, and a guid that is unique across all elements. This is a perfect match with the DSS’s  Identity that both have a long and a guid inside.

So what I did was that I made myself a mapping table using the DDS Id as the id and guid for my page provider.

The properties in my DDS table is this:

image

 

 

 

 

and my episerver.config have these elements defined. Where should we get the page structure from, and where should they be displayed

Code Snippet
  1. <pageProvider>
  2.   <providers>
  3.       <add name="Club1" type="Itera.PageProviders.SubStructurPageProvider, EPiServer.Templates.RelatePlus"
  4.         entryPoint="43"
  5.           GetChildrenFrom="6"/>
  6.   </providers>
  7. </pageProvider>

The first method I need to implement is the one that returns page references for one page reference.

Code Snippet
  1. protected override PageReferenceCollection GetChildrenReferences(PageReference pageLink, string languageID)
  2. {
  3.     if (pageLink.CompareToIgnoreWorkID(base.EntryPoint))
  4.     {
  5.         var pages = EPiServer.DataFactory.Instance.GetChildren(GetChildrenFrom,
  6.             new LanguageSelector(languageID));
  7.         return SubStructurIDs.Ensure(pages, ProviderKey, pageLink.ToString());
  8.     }
  9.     else
  10.     {
  11.         var item = SubStructurIDs.GetItem(pageLink, ProviderKey);
  12.         if (item != null)
  13.         {
  14.             var pages = EPiServer.DataFactory.Instance.GetChildren(item.ContentPage,
  15.                 new LanguageSelector(languageID));
  16.             return SubStructurIDs.Ensure(pages, ProviderKey, pageLink.ToString());
  17.         }
  18.     }
  19.     return new PageReferenceCollection();
  20. }

I call the Ensure method and that stores the page references using the DDS. And the use the Id in the DDS table to make the “new” page link.

Code Snippet
  1. public static PageReferenceCollection Ensure(PageDataCollection pages, string providerKey,string parentPageLink)
  2. {
  3.     PageReferenceCollection result = new PageReferenceCollection();
  4.  
  5.     var query = from item in Store.Items<SubStructurIDs>() where
  6.                     item.ProviderKey == providerKey &&
  7.                     item.ParentPageLink == parentPageLink
  8.                 select item;
  9.     var hash = new Dictionary<int, SubStructurIDs>();
  10.     foreach (var item in query)
  11.     {
  12.         hash.Add(item.ContentPage.ID, item);
  13.     }
  14.     foreach (var page in pages)
  15.     {
  16.         
  17.         if (hash.ContainsKey(page.PageLink.ID))
  18.         {
  19.             result.Add(hash[page.PageLink.ID].ThisPageLink);
  20.             hash.Remove(page.PageLink.ID);
  21.         }
  22.         else
  23.         {
  24.             var newItem = new SubStructurIDs();
  25.             newItem.ContentPage = page.PageLink;
  26.          
  27.             newItem.ParentPageLink = parentPageLink;
  28.             newItem.ProviderKey = providerKey;
  29.             Store.Save(newItem);
  30.             result.Add(newItem.ThisPageLink);
  31.  
  32.         }
  33.     }
  34.     if (hash.Count > 0)
  35.     {
  36.         //Need to delete, or in other lang
  37.     }
  38.     return result;
  39. }

 

The I need to implement 2 functions, one where we have the page link and the find the guid, and one that have the guid and needs to find the page Link. These to are pretty much alike, and one looks like this

Code Snippet
  1. protected override Uri ResolveLocalPage(Guid pageGuid, out PageReference pageLink)
  2. {
  3.     var item = SubStructurIDs.GetItem(pageGuid, ProviderKey);
  4.      if (item != null)
  5.      {
  6.          pageLink = item.ThisPageLink;
  7.          return CreateUri(pageLink, item);
  8.      }
  9.      pageLink = PageReference.EmptyReference;
  10.      return null;
  11. }

Then we need to return a page

Code Snippet
  1. protected override PageData GetLocalPage(PageReference pageLink, ILanguageSelector languageSelector)
  2. {
  3.      var item = SubStructurIDs.GetItem(pageLink, ProviderKey);
  4.      if (item != null)
  5.      {
  6.          PageData org = EPiServer.DataFactory.Instance.GetPage(item.ContentPage, languageSelector);
  7.          if (org != null)
  8.          {
  9.              org = org.CreateWritableClone();
  10.              org.PageLink = pageLink;
  11.              org.ParentLink = PageReference.Parse(item.ParentPageLink);
  12.              org.PageGuid = item.Id.ExternalId;
  13.              return org;
  14.          }
  15.      }
  16.      return null;
  17. }

And then we are good to go.

Full code here

Jan 28, 2011

Comments

Please login to comment.
Latest blogs
A day in the life of an Optimizely OMVP: Learning Optimizely Just Got Easier: Introducing the Optimizely Learning Centre

On the back of my last post about the Opti Graph Learning Centre, I am now happy to announce a revamped interactive learning platform that makes...

Graham Carr | Jan 31, 2026

Scheduled job for deleting content types and all related content

In my previous blog post which was about getting an overview of your sites content https://world.optimizely.com/blogs/Per-Nergard/Dates/2026/1/sche...

Per Nergård (MVP) | Jan 30, 2026

Working With Applications in Optimizely CMS 13

💡 Note:  The following content has been written based on Optimizely CMS 13 Preview 2 and may not accurately reflect the final release version. As...

Mark Stott | Jan 30, 2026

Experimentation at Speed Using Optimizely Opal and Web Experimentation

If you are working in experimentation, you will know that speed matters. The quicker you can go from idea to implementation, the faster you can...

Minesh Shah (Netcel) | Jan 30, 2026