This is my first blog about EpiServer. The problem is that I’m not familiar with all the terms used in EpiServer world and especially when talking about EpiServer 7 CMS. I’m not even sure if “custom content” is the correct term or should I write about IContent. Anyway, here’s tiny, ugly piece of code I wrote to manage custom content in EpiServer’s edit view.
Basic problem was that Epi7 doesn’t have editor for custom content. Well, there is an editor to edit single custom content’s properties but there’s no way out-of-the-box to create or delete custom content objects.
I’m using MVC framework here so code contains normal Epi elements and MVC style controller and view. Code is, like I said, very ugly but it’s working. I’m just too lazy to refactor and clean it up. I placed the code in my dropbox shared folder.
https://www.dropbox.com/sh/jesqrdrx44lrrmr/Bi_PyalN5e/EpiTest.zip
In order to use the thing you need to create a single CustomContentPage type page anywhere in the system. This page should not be shown to the end user. It should be restricted for administrative use only.
Interesting parts of the code are:
Controllers\CustomContentController
This handles all the actions needed to list custom content anywhere on the site and contains methods to create and delete them. Take notice of heavy use of reflection. I just love .NET’s reflection.
Initializers\ContentTypeInitializer
Custom content needs to be registered to EpiServer. Here I initialize my “BarContent”. BarContent implements IContent interface.
Initializers\RouteInitializer
Here I just register routes for AJAX calls. Nothing fancy.
Models\Pages\CustomContentPage
This is just a empty page type. This is needed because I implemented the editor as page in Epi’s page tree. I didn’t have time to find out how plugins are used in Epi7.
Models\ViewModels\CustomContentViewModel
View model object to store information passed between controller and view. The extension class in this file is particularly ugly but I was too lazy to find out how to do recursions in view.
View\CustomContentView
This is the view part of all this. First there is some jQuery stuff to handle button actions on client-side. Then some inline CSS because I was too lazy to write separate CSS file. Next there’s dialog template used when creating new custom content object and finally list view of all the custom content types and objects in the system.
Have fun.