Fork me on GitHub

PowerSlice


Installation

  1. Make sure that your site is running EPiServer 7 Patch 2 and the latest version of EPiServer Find.
  2. Ensure that you have EPiServer's NuGet feed added as a package source.
  3. Install the NuGet package PowerSlice.

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!

Simple example slice

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

Customizing slices

Override the Order property to control in which order the tabs for slices appear.

Override the HideSortOptions property and return true to hide the sort links.

[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));
}