Another day, another page provider

by: Allan Thræn

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: }

29 June 2010


Comments

  1. This is actually really, really useful - as long as you put a canonical tag in the markup. Yet another reason for enabling page providers in the standard Professional license, no? :)
Post a comment    
User verification Image for user verification  
Allan Thræn

About me

I am a product manager @ EPiServer, with a passion for the more geeky side of things. My technical interests are typically focused around user problems, user experience,  search, information management, artificial intelligence and  personalization

On top of this blog I have the blog Allan On Technology and I often crosspost.

DISCLAIMER: Unless otherwise stated in the posts, this blog expresses my personal opinions, experiments and views, not necessarilly the views of EPiServer AB.

 746 page views this week.

 

 

Syndications


Archive


Tag cloud

EPiTrace logger