EditFrame with Sitecore MVC and Glass.Mapper

Ever hand to deal with html which is just not compatible with the tags that glass html helpers render for you?
And in these occasions, it pretty much seems like you are going to have to say bye bye to page editor support!
EditFrame is the answer to your problems.

This is definitely not a new concept and existed in the asp.net version of sitecore libraries too.
In this post, I will demonstrate how to get this set up in your MVC site (with glass mapper).

EditFrame basically lets you make any html page editor friendly. All you need to do, is tell it which item and which field / set of fields you want to associate with the given html.

There are 2 parts to setting this up

  • Create items with the fields you want to add support for specified
  • Add the corresponding code – passing in the item which needs to be made editable, wrapped around the html which will be editable

In this example, consider a simple Product template, with a multilist field ‘Categories’

2015-06-07_013912

Core Items

In core database, under /sitecore/content/Applications/WebEdit/Edit Frame Buttons, add your field, making a duplicate of the /sitecore/content/Applications/WebEdit/Edit Frame Buttons/Default folder for convenience. This will bring over with it the below items.

2015-06-07_014505

The title and tooltip in the above screenshot will correspond to the title and tooltip of the edit frame in page editor mode when you select the editable target html.

You can then specify the fields for which you would want to add page editor support. In this example, I have mentioned only 1, but as mentioned below, you can add a pipe delimited set of multiple fields.

2015-06-07_015230

Another great advantage of this approach, of separating the fields from the items / templates here, is that you can create a single folder for common fields like say Background Image, Products, Featured Links etc, which might be reused over multiple templates!

So now in the code, you need to create the frame tag and pass in the path to this folder we created, along with the item which needs to be editable.

Following is the view code:

@using sc72
@using sc72.tdsmaster.sitecore.templates.User_Defined

@inherits Glass.Mapper.Sc.Web.Mvc.GlassView<Product>

<!-- START: Product Detail -->

<b>Sku:</b> @Editable(p => p.Sku)
<b>Name:</b> @Editable(p => p.Name)
@RenderImage(p => p.Image, isEditable: true)
@using (BeginEditFrame(ItemTree.Content.Applications.WebEdit.Edit_Frame_Buttons.Site.Status.ItemPath, Model.Id.ToString()))
{
    if (Model.Custom_Status != null)
    {
        <span><b>Status:</b> @Model.Custom_Status.Title</span>
    }
}

@using (BeginEditFrame(ItemTree.Content.Applications.WebEdit.Edit_Frame_Buttons.Site.Categories.ItemPath, Model.Id.ToString()))
{
    if (Model.Custom_Categories != null && Model.Custom_Categories.Any())
    {
        <span><b>Categories:</b> </span>
        foreach (Product_Category category in Model.Custom_Categories)
        {
            @:&nbsp;&nbsp;&nbsp;&nbsp; @category.Title

        }
    }
}

@RenderLink(p => p.Purchase_Link, isEditable: true)

<!-- END: Product Detail -->

Here’s the resultant page in pageeditor mode:

2015-06-07_015929

Here are examples of scenarios when this is particularly useful:

  • Background images
  • Page editor support for sitecore reference type fields (droplinks, treelists, multilists etc)
  • Iframes / Audio / Video tags
  • Rendering sitecore data to get plugins on your page
  • Newer html tags – picture tag / canvas – Or really any HTML for which glass might not have page editor support included html helper methods.

You can also configure the above to allow inserting new items in page editor mode!

Advertisements

, , , , , ,

  1. #1 by Abhishek Shrivastava on April 13, 2017 - 12:45 am

    Thank you for sharing!

    Like

  1. Page editor support in Sitecore for background images | Tech Musingz

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: