...

Custom Views for an Interface

Ever played around with adding custom views in Episerver CMS? It's a really powerful way to extend the UI. But why does it work when you register your view for a model class, but not for an interface implemented by that model? I had a look and found out.

Dont get your hopes up - this is just a short blog post to remind myself of a fun little detail that would otherwise cause me to probably waste an hour again some day looking for exactly the same issue.

It's a neat and pretty common thing to add custom views for your content. I've done it in a dozen integrations of various kinds, and it's described in many (!) blog posts:

Today, I was once again using the views, but I needed to have them work for an interface rather than the specific model class. Something like this:

    [ContentType(GUID = "EE3BD195-7CB0-4756-AB5F-E5E223CD9820")]
    [MediaDescriptor(ExtensionString = "pdf,docx")]
    public class GenericMedia : MediaData, IMyContentInterface
    {
        /// <summary>
        /// Gets or sets the description.
        /// </summary>
        public virtual String Description { get; set; }
    }

But when I changed it to be an interface it stopped showing up. That seemed a bit odd, so instantly I fired up dotPeek and took a look at how the Episerver views are registrered. And they are registrered towards IContentData and IContent - so why won't it work for me? Here's my view:

    [ServiceConfiguration(typeof(EPiServer.Shell.ViewConfiguration))]
    public class MyView : ViewConfiguration<IMyContentInterface>
    {
        public MyView()
        {
            Key = "myView";
            Name = "My View";
            Description = "A view with my stuff";
            ControllerType = "epi-cms/widget/IFrameController";
            ViewType = VirtualPathUtility.ToAbsolute("~/mypathtomycontroller/myview");
            IconClass = "myicon";

        }
    }

Turns out to be stupid simple: Views needs to match up their types with the proper UIDescriptors. If you don't have a UI Descriptor, then get one - even if you don't plan to use it.

This fixed the issue:

    [UIDescriptorRegistration]
    public class MyUIDescriptor: UIDescriptor<IMyContentInterface>
    {
        public MyUIDescriptor()
        {
          //Potentially set the default view or disable some other views  
        }
    }

 

Blog Posts

...

Webcast: Addons In Real Life @ CodeArt

Last week I did a couple of talks at Episerver User Group meetings in Denmark about how I've tweaked my Episerver installation at codeart.dk in order to work as a great blogging platform. I also showcase a few of the addons I'm currently working on. Now I recorded the talk, so if you have a 23 minutes to spare, then grab a coffee and make some popcorn and have a look.

...

Custom Views for an Interface

Ever played around with adding custom views in Episerver CMS? It's a really powerful way to extend the UI. But why does it work when you register your view for a model class, but not for an interface implemented by that model? I had a look and found out.

...

Admin Mode Plugin to Manage Content Type Suggestions

If you have a site with a lot of different content types, it can be a good idea to help Episervers Automatic Content Type suggestion feature along. Here is a basic Admin mode tool - in good old webforms (yes, I washed my hands after I made it) that will let administrators / and super-editors configure exactly which content types to suggest when.

...

Auto Tagging Using Search

You don't always have to go the full AI route to get AI like results. In this blog post I'll describe an approach I've used several times (and for multiple purposes) with pretty decent results. Instead of classification algorithms, deep learning or neural networks I'll just simply query my favorite search engine.

...

Which Dojo Topics are published in the Episerver CMS UI?

If you, like me are venturing into the mythical and magical world of dojo-in-episerver-ui, where elfs and wizards rule, you might also find this list useful.

...

Storage Performance Aftermath - ElasticSearch Joins the Fight

In 3 previous blog posts I compared various azure storage technologies with regards to performance and scalability in typical web usage scenarios. I was actually done with the series, but with all that interesting data, I decided to throw my current favorite search/storage/no-sql technology into the mix to get an idea about how it all compares. So - ElasticSearch enters the competition!

...

Azure Storage Performance Showdown (Post 3)

This is the 3rd post in my Azure Storage Performance comparison. So far we've examined the typical scenario of storing/retrieving data that most dynamic websites of today deal with. In this post, we'll take a closer look at Update and Delete - and finally review the financial aspects.

...

Azure Storage Performance Showdown (Post 2)

In this second post of my performance series looking at Azure storage we're going to take a good look at Read speeds for the various storage types.

...

Content Providers and Flat Content

A classic challenge in many CMS - and also in Episerver - has always been what do you do with large amounts of non-hierarchical/flat content?  There has been many workarounds along the way and I was just on my way to make yet another when I discovered a well hidden secret deep in the belly of Episervers UI: The Asset widget (that holds blocks and media items) does in fact have infinite scrolling - which in turn can support incredibly large flat structures!

...

Azure Storage Performance Showdown (Post 1)

Almost every project has some data you want to persist, then read, search through, update and eventually delete. With Azure there are loads of great possibilities - for example Blob Storage, Table Storage, CosmosDb, SQL Azure. I've decided to do some simple and fairly naive tests to compare these for some typical usage scenarios and see how they perform.

...

Understanding Episerver CMS - How are images rendered

When using reusable content such as images, the actual HTML rendering of them can happen multiple places. But when is what used? And how can you customize it?

...

VS2017 Debugger Timeout

A really annoying problem has been bothering me for a while with VS2017. When debugging most web apps, I often encounter time-outs. For some reason it happens nearly every time I do it with Episerver projects. Here is the solution.

Post Comments()