November Happy Hour will be moved to Thursday December 5th.

Views: 15027
Number of votes: 10
Average rating:

Re-introducing PowerSlice for Episerver CMS

Some time ago Joel Abrahamsson created PowerSlice for Episerver. A lot has happened with the Episerver platform since then, and now we are re-introducing PowerSlice to match the latest and greatest version Episerver. Expanding the page tree to locate a page can be time consuming on large websites with hierarchical navigation structures. PowerSlice provides a different way of listing and managing content, suitable for sites with large numbers of pages and blocks. PowerSlice is also useful for content that does not naturally fit into a hierarchical structure, for example news and articles on media sites, and blog postings.

A special thanks goes to Viktor Sahlström for code samples and the awesome demo video!

PowerSlice for editors

How does it work? PowerSlice lets developers divide website content into slices based on its properties. This is then used for creating customized super fast content filtering. PowerSlice is made available to editors as a gadget that can be added to the panes in CMS edit view. 

The slices you see are filtered on the logged in user and content type. In the example below "slices" are applied for pages, blocks and articles, but more filters can be added. Content within a selected slice can be searched, as well as sorted based on name and publish date.

Content can be created directly from the PowerSlice gadget, and you can use the slices in the gadget to add for instance blocks to a page that you are creating. 

PowerSlice for developers

Installing and using PowerSlice for Episerver CMS is easy, follow the steps below to get started.

Note: PowerSlice requires an Episerver Find license because EPiServer.Find is a dependency.

Installation

Ensure that you have the Episerver NuGet feed added as a package source in Visual Studio, and then install the PowerSlice package.

Creating a slice

  1. Create a class inheriting from ContentSliceBase<T> (T is the type you want to list, can be IContentData, PageData, MyFunkyPage etc).
  2. Implement the Name property.
  3. Annotate the class with
    [ServiceConfiguration(typeof(IContentQuery)), ServiceConfiguration(typeof(IContentSlice))]
  4. Done!
       

Customizing slices

  • Override the HideSortOptions property and return true to hide the sort links.
  • Override the Order property to control in which order the tabs for slices appear
    [ServiceConfiguration(typeof(IContentQuery)), ServiceConfiguration(typeof(IContentSlice))]
    public class CategoriesSlice : ContentSliceBase<CategoryPage>
    {
      public override string Name
      {
        get { return "Categories"; }
      }
      public override int Order
      {
        get { return 5; }
      }
      public override bool HideSortOptions
      {
        get
        {
          return true;
        }
      }
    }

Enable content creation

  • Override the CreateOptions property and return one or more CreateOptions.
  • Each option requires a name/label, a content type and a parent for the new content.
    public override IEnumerable<CreateOption> CreateOptions
    {
      get
      {
        var contentType = ContentTypeRepository.Load(typeof (TagPage));
        var startpage = ContentLoader.Get<StartPage>(ContentReference.StartPage);
        yield return new CreateOption(contentType.LocalizedName, startpage.TagsRoot, contentType.ID);
      }
    }


Filter content

The type argument to the base class is just the first filter, you can add more.

protected override ITypeSearch<EditorialPageBase> Filter(
  ITypeSearch<EditorialPageBase> searchRequest,
  ContentQueryParameters parameters)
{
  return searchRequest.Filter(x => x.Created.MatchYear(DateTime.Now.Year));
}

Example slices

The examples below are used in the PowerSlice demo video [LINK]

My pages

[ServiceConfiguration(typeof(IContentQuery)), ServiceConfiguration(typeof(IContentSlice))]
  public class MyPagesSlice : ContentSliceBase<SitePageData>
  {
      public override string Name
      {
        get { return "My Pages"; }
      }
      protected override ITypeSearch<SitePageData> Filter(ITypeSearch<SitePageData> searchRequest, ContentQueryParameters parameters)
      {
        var userName = HttpContext.Current.User.Identity.Name;
        return searchRequest.Filter(x => x.MatchTypeHierarchy(typeof(IChangeTrackable)) & ((IChangeTrackable)x).CreatedBy.Match(userName));
      }
  }

Blocks

[ServiceConfiguration(typeof(IContentQuery)), ServiceConfiguration(typeof(IContentSlice))]
  public class BlocksSlice : ContentSliceBase<SiteBlockData>
  {
    public override string Name
    {
      get { return "Blocks"; }
    }
  }

Articles

[ServiceConfiguration(typeof(IContentQuery)), ServiceConfiguration(typeof(IContentSlice))]
  public class ArticleSlice : ContentSliceBase<ArticlePage>
  {
    public override string Name
    {
      get { return "Articles"; }
    }
    public override IEnumerable<CreateOption> CreateOptions
    {
      get
      {
        var contentType = ContentTypeRepository.Load(typeof(ArticlePage));
        yield return new CreateOption(contentType.LocalizedName, ContentReference.StartPage, contentType.ID);
      }
    }
  }

Pages

[ServiceConfiguration(typeof(IContentQuery)), ServiceConfiguration(typeof(IContentSlice))]
  public class PagesSlice : ContentSliceBase<StandardPage>
  {
    public override string Name
    {
      get { return "Pages"; }
    }
  } 

Related information

Comments

Justin Le
Justin Le Jan 21, 2015 10:59 AM

Really nice!!!!

Jan 29, 2015 11:19 AM

Great stuff.

Mikael Johansson
Mikael Johansson Feb 2, 2015 08:37 AM

Brilliant, indeed brilliant.

Milos Malic
Milos Malic Feb 6, 2015 10:43 AM

Currently working on a site with big tree where some nodes have lot of children. This could be great help. Thanx for sharing.

Ted
Ted Sep 29, 2015 03:59 PM

With the release of EPiServer CMS 9 we get a dependency to Find >10, whereas PowerSlice currently has a dependency to Find <10.>

Any plans for upgradering the PowerSlice add-on to support version 10+ of Find?

Mar 15, 2016 09:01 PM

I ran nuget command  Install-Package PowerSlice on site with CMS version 9.6.1.0 and got below error:

Install-Package : Updating 'EPiServer.Framework 9.6.1' to 'EPiServer.Framework 8.0.0' failed. Unable to find a version of 'EPiServer.CMS.Core' that is compatible with 'EPiServer.Framework 8.0.0'.
At line:1 char:1
+ Install-Package PowerSlice
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], InvalidOperationException
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand

Does this mean that Powerslice is supported  below version 9 and above 7 or have i done something wrong, Please assist.

Aziz Khakulov
Aziz Khakulov Mar 7, 2017 02:32 PM

Would be nice if I could do batch actions. For example, I created a slice for listing the unused blocks. I would like to select all those and delete them. Is that possible to do?

Please login to comment.