3

I need an alternate for the EditorTemplate of an Enumerator Field that's used when the Field has a particular name (PublishingMethod).

Based on the docs, I created a view with the pattern [ShapeType__FieldName] in the same folder as the original shape:

Alternate Template

This is not working and still uses the original. I've thought of changing the Editor method in the Driver, but I think that defeats the purpose of alternates, which is that Orchard automatically detects the correct shape as I understand from the docs:

The Orchard framework automatically creates many alternates that you can use in your application. However, you can create templates for these alternate shapes.

Note: I can't use the Shape Tracing module, it never worked even with a clean Orchard install.

4

1 回答 1

3

Orchard 中的编辑器的工作方式与 Display 的工作方式不同。我想这是为了让您获得 MVC 风格的体验。基本上,返回的实际形状是 EditorTemplate 类型,然后绑定您的模型和前缀,然后使用您给它的模板名称呈现局部视图。这意味着替代品不会按预期或文档状态工作。您的字段名称的替代项实际上已添加到 EditorTemplate 形状中。所以你可以做的是添加一个名为的视图EditorTemplate-PublishingMethod.cshtml,其内容如下:

@{ 
    var m = (Orchard.Fields.Fields.EnumerationField)Model.Model;
}

@Html.Partial("PublishingMethodEditor", m, new ViewDataDictionary {
    TemplateInfo = new TemplateInfo { HtmlFieldPrefix = Model.Prefix }
})

然后添加另一个视图,调用PublishingMethodEditor.cshtml您想要的编辑器的覆盖。所有这些视图都应该放在 Views 文件夹的根目录中。

另一种方法是实现IShapeTableProvider接口并TemplateName在特定条件下调整属性,但是,嗯,这需要代码......

编辑 1 如果您在不想覆盖的其他内容类型上有该字段名称,则可以使用覆盖EditorTemplate-ContentTypeName-PublishingMethod.cshtml

于 2018-01-25T14:19:16.383 回答