Sunday, June 19, 2016

Sitecore Editor Panels

When working on features for clients, there are times when a need arises to create a custom tool.  Often the first instinct is to create a SPEAK app.  This is not always the best solution.  Sometimes you need something a bit more context aware and seamless in its integration.  This is where editor panels come in to play.  In reality I find that an editor panel is often far easier to create, and that it can create a better user experience.

There are many editor panels that we use every day, such as the one that shows up when you select a folder which gives you options of items to insert as well as shows the child items.  A media folder is similar by having buttons to upload media.  Sometimes there are features of a site that may be better managed in the context of that feature, even though all the data for that feature is not necessarily in one place.

Creating an editor panel is a simple process, you simply need to create a page and point an item in the core database to it.  The page does not really have many rules as Sitecore will simply load it in an iframe.  There are several parameters that are passed to the page such as language, version, id, and database.  If you need the context of the website, you will need to find that or fake it in the context.  That is a topic for a different post though.

To keep this short, I am going to assume that you can create a page and access the parameters passed in.  This could even be multiple pages since it is in the context of an iframe.  All you need to do is create an editor item in Applications/Content Editor/Editors, and point it to your page.  To have it load on an item, you need to go onto the item (or the standard values of that item template) and add it in the Editors field.  It really is as simple as that.

An editor like this can work very well for imports, and on bucketed data as you can create a view for the data and even a way to edit it in a structured way that is more efficient than navigating the entire bucket.

Saturday, April 23, 2016

Using Sitecore xDB with a ASP.NET Handler (ashx file)

In Sitecore using xDB requires a Session in order to maintain the context as I have mentioned in my previous posts about using xDB without an active Session.  While it is possible in a handler to persist data without the Session, it is definitely preferred as it is far more reliable than any methods you can use to work around it.

By default in .NET a handler does not maintain the Session as it is intended to be very light weight. This is very easy to resolve though by simply making it inherit IReadOnlySessionState or IRequiresSessionState.  Once your handler inherits one of those interfaces it will get the Session and xDB will work.