...

Another day, another page provider

Here’s a little quick one. A page provider that doesn’t contain any pages, but simply replicates a structure found elsewhere in your page tree.

image

It’s registered very simple in episerver.config, only custom setting is which “root” is should replicate the structure from.

   1: <pageProvider>
   2:     <providers>
   3:       <add name="ShortcutProvider" type="EPiServer.PageProvider.PageListProvider,EPiServer.Templates.Public" entryPoint="26" root="16"/>
   4:       
   5:     </providers>
   6:   </pageProvider>

Code is here – as usual, use on own risk. Provided AS-IS.

 

   1: using System;
   2: using System.Collections.Generic;
   3: using System.Linq;
   4: using System.Web;
   5: using EPiServer.Core;
   6:  
   7: namespace EPiServer.PageProvider
   8: {
   9:     public class PageListProvider : PageProviderBase
  10:     {
  11:         private PageReference rootPage;
  12:  
  13:         public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
  14:         {
  15:             base.Initialize(name, config);
  16:             rootPage = PageReference.Parse(config["root"]);
  17:         }
  18:  
  19:         protected override PageReferenceCollection GetChildrenReferences(PageReference pageLink, string languageID)
  20:         {
  21:             return new PageReferenceCollection(DataFactory.Instance.GetChildren(rootPage, new LanguageSelector(languageID)).Select(pd => pd.PageLink));
  22:         }
  23:  
  24:         protected override PageData GetLocalPage(PageReference pageLink, ILanguageSelector languageSelector)
  25:         {
  26:             return DataFactory.Instance.GetPage(pageLink, languageSelector);
  27:         }
  28:  
  29:         protected override void SetCacheSettings(PageData page, CacheSettings cacheSettings)
  30:         {
  31:             cacheSettings.CancelCaching = true;
  32:         }
  33:  
  34:         protected override void SetCacheSettings(PageReference pageLink, PageReferenceCollection childrenReferences, CacheSettings cacheSettings)
  35:         {
  36:             cacheSettings.CancelCaching = true;
  37:         }
  38:  
  39:         protected override Uri ResolveLocalPage(PageReference pageLink, out Guid guid)
  40:         {
  41:             guid = Guid.Empty;
  42:             return null;
  43:         }
  44:  
  45:         protected override Uri ResolveLocalPage(Guid pageGuid, out PageReference pageLink)
  46:         {
  47:             pageLink = PageReference.EmptyReference;
  48:             return null;
  49:         }
  50:     }
  51: }

Post Comments()