Glass Edit Frame – Immediately Invoking Wrapper

tl;dr; Custom HTML Helper to wrap Glass Edit Frame and JS code to immediately open the modal dialog for editing

As I’m sure most of you are aware, I 😍 Glass Mapper. So much so that I struggle with the native Sitecore API 😂 

Version 4 of the framework added an amazing feature which allows you to very simply and quickly create/bind to Edit Frames purely from code. Normally this is a bit of an annoying and long winded processing: switch over to the core database, create an item with names of the fields, serialize/sync to source control, do this for every combination of fields you have, hook it up to EditFrame code that until recently did not work in native Sitecore MVC 😆

I’m sure you’ve been using this feature, it’s super simple from code to add an EditFrame wherever you need and the best part is it’s bound against your strongly typed model:

@using (BeginEditFrame(Model.Page, "Edit Metadata", x => x.DisplayInMenu, x => x.Closed))
{
  <div>Let's add an Edit Frame around our rendering</div>
}

If you need to add another field then simply add it to the list of fields and Glass handles everything for you.

Read More

Advertisements

Custom Glass.Mapper Data Handlers – Part 2

In a previous post about extending Glass Mapper to handle custom data types I shared some code which I felt was overly verbose and I did not like the amount of code that had been copy/pasted. The example I used was a fairly trivial one, but it’s always good practice to try avoid copy/paste in case some point in the future the base implementation is changed. It might not always be clear to future developers how that piece of code had come about.

In that original post, Mike Reynolds (a.k.a sitecorejunkie) suggested use of the Decorator Pattern to wrap an instance of the base mapper and delegate some of the methods. Well it got me feeling uneasy and I finally found a little time to come back and clean that code up, I went a slightly different route and decided to use constructor overloading.

Read More

Extending Media Item Templates with Custom Glass.Mapper Data Handlers

On a recent project I needed to add a couple of fields to Media Items templates in order store some additional data. We are using the Glass Mapper ORM in our project and out of the box there are two fields which we can map to: Image and File. I also needed to retrieve the file size, which neither of these fields returned either.

It turned out to be relatively simple to extend Glass Mapper and add our own custom data handler to map the additional fields.

Read More

Upgrade Sitecore Glass Mapper from v2 to v3

I recently upgraded a project from Glass Mapper v2 (Glass.Mapper.Sitecore) to Glass Mapper v3 (Glass.Mapper.Sc). I’ve been fortunate enough to be using Team Development for Sitecore (TDS) with most of my projects over the past few years, which really simplifies generating a default set of Glass Models using the T4 Templates which are available from the Hedgehog Codegen repo on GitHub. The upgrade process was simple enough (NuGet FTW!) but thought I would share some issues I came across that took a little bit of time to resolve.

The upgrade was to fix some unrelated issues we were facing, but since the v2 Glass project seems to have disappeared off the face of the earth (annoying that an entire GitHub repo just gets deleted like that rather than left for historical purposes…) it seemed like a good idea to remove this dependency at the same time.

Read More