how to render editor using the new IShapeDisplay

Topics: Customizing Orchard, Troubleshooting
Oct 21, 2014 at 9:34 AM
I created a service to return the html output of a content item in order to inject the html through javascript. I am trying it using the new IShapeDisplay service which is injected into the service.The method body looks like this
  public   string BuildOrchardEditor(int orchardcontentitemid,  int viewmode )
            //get content item
            //build shape
           // turn shape into string and return 
            dynamic shape = null; 
            var contentItem = _contentManager.Get(orchardcontentitemid);

            if (viewmode == 0)
                shape = _contentManager.BuildDisplay(contentItem);
            else if (viewmode == 1)
                shape = _contentManager.BuildEditor(contentItem);
            if (shape != null)
                return _shapeDisplay.Display(shape);
            return "";

it works fine for BuildDisplay:
shape = _contentManager.BuildDisplay(contentItem);

but does not work for BuildEditor:

shape = _contentManager.BuildEditor(contentItem);

The error is caused in CoreShapes.cs in method

public void EditorTemplate(HtmlHelper Html, TextWriter Output, string TemplateName, object Model, string Prefix) {}

where the HtmlHelper.View property is null (Html.ViewContext.View)

Is this a bug or intended to be this way?
Is there some workaround so we can consistently grab the html output of a content item (both display or editor) in a string for Single Page Application scenarios?

Oct 21, 2014 at 4:42 PM
You should look into the Customform module which does exactly that.
Oct 21, 2014 at 5:24 PM
Thanks sebastien,
yeah, I looked into it.

But this only works in the scope of a controller since its calling code like this
   var model = _contentManager.BuildEditor(contentItem);


            return View(model);
It does not suite the case for getting the html content outside of a controller , like a service in my case.