Monday, December 14, 2009

Show/hide GuiPlugin in EPiServer

To make a plugin only show on specific pages follow these steps.

1. Create your plugin as usual.
2. Implement the ICustomPluginLoader interface.
3. Return a empty PluginDescriptor[] in the List() function for all pages that you don’t want the plugin to be visible.

In the example below the plugin is only visible for the startpage.

[GuiPlugIn(DisplayName = "Rates & Indexes", 
 Description = "Edit rates and indexes", 
 Area = PlugInArea.EditPanel, 
 Url = "~/RatesAndIndexes/RatesAndIndexes.ascx")]
public partial class RatesAndIndexes : System.Web.UI.UserControl, ICustomPlugInLoader
{
 public PlugInDescriptor[] List()
 {
  EPiServer.UI.Edit.EditPanel editPanel = (EPiServer.UI.Edit.EditPanel) System.Web.HttpContext.Current.Handler;    
  if (EPiServer.Core.PageReference.StartPage.ID != editPanel.CurrentPage.PageLink.ID)
  {
   return new PlugInDescriptor[] { };
  }
  else
  {
   return new PlugInDescriptor[] {  PlugInDescriptor.Load(this.GetType()) }; }
  }
 }
}
Share:

0 kommentarer:

Post a Comment