How to define part editor alternates

Topics: Customizing Orchard
Feb 22, 2013 at 2:08 PM
Now, the shape from the partdriver is EditorTemplate, can not define the editor shape alternates

How to define it?

example the "Parts_Title_Edit", i want to define the alternates like this" Parts_Title_Edit__Page" and the template name is 'Title.Edit-Page.cshtml", the "Page" is a Content Type
Coordinator
Feb 23, 2013 at 12:53 AM
What's the scenario where you need to do that?
Feb 23, 2013 at 3:23 AM
example: I want "Parts_Title_Edit" template in the Page content type editor,
like this "@Html.TextBoxFor(model => model.Title, new { @class = "large text", autofocus = "autofocus" })
and
like this "@Html.TextBoxFor(model => model.Title, new { @class = "other other-1 other-2 other-3 other-4 other-5", autofocus = "autofocus" })" in the other content type editor

I mean "Parts_Title_Edit" has alternates like "Parts_Title"

Now it's Shape is "EditorTemplate" in the code
return ContentShape("Parts_Title_Edit",
                () => shapeHelper.EditorTemplate(TemplateName: "Parts/Title", Model: part, Prefix: Prefix));
I changed it
return ContentShape("Parts_Title_Edit",
                () => shapeHelper.Parts_Title_Edit(Model:part));
it not run
Feb 23, 2013 at 3:30 AM
Edited Feb 23, 2013 at 3:34 AM
I had a error
Coordinator
Feb 23, 2013 at 4:12 AM
what error?
Feb 23, 2013 at 9:09 AM
Edited Feb 23, 2013 at 9:38 AM
The model item passed into the dictionary is of type 'Orchard.DisplayManagement.Shapes.Shape', but this dictionary requires a model item of type 'Orchard.Core.Parts.Models.TitlePart'. 

DisplayManagement\Descriptors\ShapeTemplateStrategy\ShapeTemplateBindingStrategy.cs    line:  149 

var result = htmlHelper.Partial(harvestShapeInfo.TemplateVirtualPath, displayContext.Value);
Coordinator
Feb 23, 2013 at 10:03 AM
Right: the template that ends up rendering this shape has the wrong model type.
Feb 23, 2013 at 12:51 PM
How to fix it ?

I think the part editor alternate is important in some scenario
Developer
Feb 23, 2013 at 1:00 PM
When implementing the Editor methods, you need to return an EditorTemplate shape, so you need to revert your code from:
return ContentShape("Parts_Title_Edit", () => shapeHelper.Parts_Title_Edit(Model:part));
To:
return ContentShape("Parts_Title_Edit", () => shapeHelper.EditorTemplate(TemplateName: "Parts/Title", Model: part, Prefix: Prefix));
Feb 23, 2013 at 1:26 PM
It is current implementation in orchard,

but the shape is EditorTemplate, and it's alternates are "EditorTemplate-Page.cshtml" or "EditorTemplate-[id].cshtml,

there isn't part editor alternates ,

Why we do not need part editor alternates?
Developer
Feb 23, 2013 at 2:34 PM
Edited Feb 23, 2013 at 2:35 PM
I didn't say we didn't need part editor alternates, I was simply trying to explain how to solve the error ("The model item passed into the dictionary is of type 'Orchard.DisplayManagement.Shapes.Shape', but this dictionary requires a model item of type 'Orchard.Core.Parts.Models.TitlePart").

To add alternates to the EditorTemplate, you probably have to write your own IShapeTableProvider or use Piedone's Helpful Libraries: http://helpfullibraries.codeplex.com/SourceControl/changeset/a54e15432b86.

It looks like there's an issue with that though, so you may want to vote for its resolution here: http://orchard.codeplex.com/workitem/19479