Search code examples
sitecoresitecore8glass-mapper

Clearing Sitecore link field rendered with Glass.Mapper.Sc BeginRenderLink removes wrapped fields


We're using Sitecore 8.0 Update 3 with Glass.Mapper.Sc 4.1.0.64 and are having an issue in the Experience Editor with Images which are wrapped within a Link.

In our View Rendering, we've got:

@using (Html.Glass().BeginRenderLink(x => x.ImageLink, isEditable: true))
{
    @Html.Glass().RenderImage(x => x.Image, isEditable: true)
}

When both the Link and Image fields are populated, this correctly renders the Image within the Link and the Experience Editor works as expected placing the relevant Link and Image editor buttons on the toolbar when clicking on the Image.

However, when the link is removed by clicking the Clear Link toolbar button, the entire Image is removed from the page meaning the Image field cannot be edited. On saving/reloading the page, the editable Image field is re-rendered correctly.

Is there a way to avoid removing the Image field when clearing the link?


Solution

  • You could render your link as non-editable and use an EditFrame for your editors. Glass has good support for Editframes (you can check the tutorials or some blogs) and it's an easy setup. You can even choose to add the image to the EditFrame as well.

    It's more a workaround than a solution though.