Optimizely (Episerver): Split folder structure for blocks and media

blog header image

Since version 7 or 8 of Episerver (now Optimizely CMS), the shared Blocks and Media have been sharing the same folder structure. Some people see a benefit with the shared structure, and some absolutely hate it. Personally, I have gotten used to it - but I was recently asked if it's possible to split it up. Here's the hack I came up with.

First of all, fair warning: This is very experimental and I'm not exactly sure of all the consequences of this hack, so if you plan to use it - do so at your own risk (but feel free to leave a comment below with the good, bad and ugly). It hasn't been tested in a multi-site scenario and most likely won't work ideal there (although the code should be pretty easy to adjust for that). Also, it doesn't migrate any existing blocks or media - so that should be done before hand.

The basic approach I took was to create 2 folders in the root of the GlobalBlockFolder - one for Media and one for Blocks. Afterwards I basically just needed the Blocks and Assets widget to use the new folders as their root. They both use an IContentRepositoryDescriptor for that, so it was pretty straightforward to create a new descriptor for each (inheriting their original), overriding the root and then using an IConfigurableModule to intercept the original calls using Dependency Injection.

The example below is not very optimized - but it does seem to work. If the folders doesn't exist, it will create them - and then make sure the widgets use them.

Recent posts