Powerslice: Identify unused blocks

...

Powerslice might have a few years on it's back, but it's still a great editorial tool, when you are working with large amounts of content and have access to Episerver Find. Here's an example of a recent slice I made that let's editors easily identify unused blocks.

Powerslice is a nice widget that gives the editors an alternative to the classic tree navigation when working with content.

In the backend it is powered by Episerver Find, and as a developer it's pretty easy to extend with your own views of the content.

Typical extension points are:

  1. Slices with different filters for content. For example a slice that lists all ArticlePages that are not 'Shortcut to another page'. Or a list of blocks that was created by the current editor - or maybe a list of all the pages that does not have proper SEO meta-data set?
  2. Custom sort orders for the slices. Maybe you want to sort by content type? Or what about showing the oldest published content (that probably needs a rewrite)? Sometimes it could also be interesting to see a list of blocks sorted by which are used in the most places (example below).
  3. Finally you can also provide editors with a shortcut to create content of a specific type in a specific location. For example, when they are looking at a slice of all Blog Posts, you can let them create a new blog post in the correct location - straight from the widget.

A client of mine had a specific problem that I think many others can recognize. They have many blocks - placed all over the possible structure - and they need to clean them out a bit - evaluate the unused ones to see if they should be deleted or archived. So - here is one approach I made to this problem:

Initial challenge is that the usages of a block is not stored on the block itself, and as such it's not indexed in Find and cannot be filtered on. But luckily that's easy to overcome.

I began by creating an extension method for IContent that would essentially return the number of times a content was referenced / used in other content, following a reverse lookup in the SoftLink Repository.

Now, before you start yelling "But Allan, how dare you use the ServiceLocator.Current in a public blog post?" just know, that I tend to take a more pragmatic approach than a dogmatic approach - especially when I want to keep it in a pretty, little extensionmethod - you feel free to pick your own way.

Next, the trick is simply during initialization to configure an indexing convention in Find where you specify that the extension method is to be included when indexing objects of the type you want to add this value to. 

Finally, it's just a matter of doing a basic Episerver Find filtering query in the right place in the slice using our new number.

For pure bonus, I also included a sample of an All-Blocks slice, that will allow you to sort based on how frequently the blocks are used - as that may also come in handy.

Enjoy!

Post Comments()

You might also like