This project is read-only.

Using editor shapes on the front end

Topics: Writing modules
Sep 16, 2011 at 2:43 PM

Moving from this discussion about the showcase site.

So when I built the uSubmit module I did it by creating a standard MVC controller/view for displaying and processing the front-end form that accepts the user input. When the form is posted to the controller I create an instance of the UserSubmission content type and map the values to the various parts on the content item. Of course, all of those parts already have editor shapes and editor methods in their drivers which handle the same thing from the Edit view in the dashboard. Sebastien pointed out that I should be able to render the editor shapes from a front-end controller, so I tried it (just using BlogPost as an example).

public ActionResult TestEditors() {
    var blogPost = _contentManager.Create("BlogPost", VersionOptions.Draft);
    dynamic editor = _contentManager.BuildEditor(blogPost);
    return View(editor);
And the view for TestEditors simply calls @Display(Model). And sure enough, this renders the editor templates for all the parts of BlogPost on the front-end of the site. Of course, the shapes are all just called "EditorTemplate" so I'm not sure if I'll have the ability to control them with - haven't tried that yet. And of course, there's no form wrapping all of the fields that the editor shapes render, so I'd have to add that. So I guess I'm wondering if anyone else has done this, or at least what people think about trying to do this? It looks like it might require duplicating some core Orchard logic in my module. Of course, the other way I'm duplicating some of my own logic, so I'm not sure that matters.

Sep 16, 2011 at 2:56 PM
Edited Sep 16, 2011 at 2:57 PM

Okay, I already answered one of my own questions. I can control the editor shapes with Even though shape tracing shows them as "EditorTemplate" you can use the string name given to the shapes. For example, the RoutePartDriver returns this from it's Editor method:


return ContentShape("Parts_Routable_Edit",
                () => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix));

I need to refresh my memory - what's the difference between the string name passed to ContentShape and the method name used on shapeHelper? Anyway, I can place Parts_Routable_Edit with my theme's Of course, I would also need to override it because we wouldn't want the end user to be able to modify the slug that it generates. It looks like I can override it in a theme, but I'd want to do this from the uSubmit module, which I don't think I could do. So I guess I'm back to thinking that it's not really worth trying to reuse the editor templates and driver methods. In other words I think my original plan still makes the most sense. Thoughts?

Sep 16, 2011 at 5:00 PM

It could also be interesting to define an alternate for the front end, useful for the to hide some parts, and to override some rendering ...

Sep 16, 2011 at 5:26 PM

I did this for the Forum module I wrote. I basically hid the default one and wrote my own.

Sep 16, 2011 at 5:31 PM

Wait, what did you do for the Forum module Nick? You hid what ... the Routable_Edit shape? I didn't think you could do that from another module, only a theme.

Sep 16, 2011 at 7:08 PM

Hey Kev,

I did this..

  <Match ContentType="Thread">
    <Place Parts_Routable_Edit="-"/>

within my file in my Forum module

Sep 16, 2011 at 7:38 PM

Interesting ... I didn't think you could do that from another module. Can you override any other module like that, or is it maybe just Core modules?

Anyway, are you using editor shapes to generate the forms on the front-end of your site? I suppose I should just dig into your module ...

Sep 16, 2011 at 7:51 PM

Okay, just browsed through your code a little bit and see that you are doing that. I hadn't done that before ... now starting to rethink how I built the uSubmit module.