Shape from Driver.Editor

Topics: Writing modules
Jul 21, 2011 at 10:46 AM

Hello.
As I understand, then I override Editor method in my module driver I get a shape named EditorTemplate, but shape with this name can't be overriden by a theme. Then I try to create an Alternate by DesignerTools I receive an exception: The relative virtual path 'Orchard.Core.Shapes.CoreShapes::EditorTemplate' is not allowed here.
I want to edit data from user pages not only from Dashboard. That I must do to get other shape name?

Jul 21, 2011 at 2:30 PM
Edited Jul 21, 2011 at 2:31 PM

I might be completely wrong here, but I assume you think it is called EditorTemplate because you have something like this in your Editor method:

 

return ContentShape("Parts_SomePart_Edit",
	() => shapeHelper.EditorTemplate(
        	TemplateName: "Parts/SomePart",
                Model: viewModel,
                Prefix: Prefix
));

 

This looks *similar* to how it is done in the Display method as well:

 

return ContentShape("Parts_SomePart",
	() => shapeHelper.Parts_SomePart(
			Part: part
));

 

In both cases, the name of the resulting shape is is first argument to ContentShape ("Parts_SomePart_Edit" and "Parts_SomePart" respectively).

The difference between the two is that the Editor method calls shapeHelper.EditorTemplate() and passes in the name of the template. In the Display method, it calles shapeHelper.Shape_Name (IIRC in this case it just looks up the view that corresponds to Shape_Name, but ultimately it is called whatever the first argument you give to ContentShape() is). So, your editor shape isn't called EditorTemplate - you just call EditorTemplate() to tell Orchard you want an Editor shape, and you also have to tell it the name of the Shape you should use to create it.

Jul 22, 2011 at 1:57 PM

Ok, I have this piece of code:        
return ContentShape("TestPart_Edit", () => shapeHelper.EditorTemplate(TemplateName: "Parts/TestPart", Model: BuildEditorViewModel(part), Prefix: Prefix)); 
This code I want to use everywhere, not only in dashboard. As result I have a shape with name EditorTemplate which can't be overriden by theme.

Jul 22, 2011 at 3:48 PM

I think you will need two shapes - one for the admin dashboard editor and one for the front end version. AFAIK you should only be using the EditorTemplate override and using the EditorTemplate method on the shape helper when you are returning a shape that is actually a content editor.

For a start, your front-end shape will need to include stuff like:

@using(Html.BeginForm("Action", "Controller", FormMethod.Post))
{
    form stuff

Whilst an editor shape doesn't need that as the Orchard content editing bits and pieces take care of it all for you (look at the editor view for any existing content part - it will not have Html.BeginForm).