我正在使用 Orchard 1.9.3 并遵循一些关于如何在 Orchard 中创建自定义普通元素的教程。我找不到任何关于创建容器元素的具体内容,所以我在源代码中挖掘了一下,这就是我到目前为止所拥有的:
元素/过程.cs
public class Procedure : Container
{
public override string Category
{
get { return "Content"; }
}
public override string ToolboxIcon
{
get { return "\uf0cb"; }
}
public override LocalizedString Description
{
get { return T("A collection of steps."); }
}
public override bool HasEditor
{
get { return false; }
}
}
驱动程序/ProcedureElementDriver.cs
public class ProcedureElementDriver : ElementDriver<Procedure> {}
服务/程序模型图
public class ProcedureModelMap : LayoutModelMapBase<Procedure> {}
视图/LayoutEditor.Template.Procedure
@using Orchard.Layouts.ViewModels;
<div class="layout-element-wrapper" ng-class="{'layout-container-empty': getShowChildrenPlaceholder()}">
<ul class="layout-panel layout-panel-main">
<li class="layout-panel-item layout-panel-label">Procedure</li>
@Display()
@Display(New.LayoutEditor_Template_Properties(ElementTypeName: "procedure"))
<li class="layout-panel-item layout-panel-action" title="@T("Delete {{element.contentTypeLabel.toLowerCase()}} (Del)")" ng-click="delete(element)"><i class="fa fa-remove"></i></li>
<li class="layout-panel-item layout-panel-action" title="@T("Move {{element.contentTypeLabel.toLowerCase()}} up (Ctrl+Up)")" ng-click="element.moveUp()" ng-class="{disabled: !element.canMoveUp()}"><i class="fa fa-chevron-up"></i></li>
<li class="layout-panel-item layout-panel-action" title="@T("Move {{element.contentTypeLabel.toLowerCase()}} down (Ctrl+Down)")" ng-click="element.moveDown()" ng-class="{disabled: !element.canMoveDown()}"><i class="fa fa-chevron-down"></i></li>
</ul>
<div class="layout-container-children-placeholder">
@T("Drag a steps here.")
</div>
@Display(New.LayoutEditor_Template_Children())
所有这些都或多或少地从 Row 元素中复制而来。我现在有一个Procedure
元素,我可以从工具箱拖到我的布局上,但它没有用我的模板呈现,即使我可以通过这种方式覆盖其他布局元素的模板,我仍然无法将任何子元素拖入它。我曾希望简单地从继承Container
就可以做到这一点。
我基本上只是想制作一个更具限制性的 Row 和 Column 对,以将一些自定义样式应用于任意内容列表。我如何告诉 Orchard 一个程序只能包含在一个列中并且它应该接受Steps
(或其他一些元素)作为子项?