我以前在其他内容部分有过这个问题(不记得是哪一个),但你可以做的是采取以下步骤:
1创建一个自定义的一部分,并记录附加到具有ContainerPart的内容类型:
public CustomContainerPart : ContentPart<CustomContainerPartRecord> {
public string DisplayType {
// property setter and getter
}
}
2创建附加的CustomContainerPart上有ContainerPart的内容类型的处理程序:
public class CustomContainerPartHandler : ContentHandler {
private readonly IContentDefinitionManager _contentDefinitionManager;
public CustomContainerPartHandler(IContentDefinitionManager contentDefinitionManager) {
_contentDefinitionManager = contentDefinitionManager;
}
protected override void Activating(ActivatingContentContext context) {
base.Activating(context);
// weld the CustomContainerPart dynamically, if the type has the ContainerPart
var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(context.ContentType);
if (contentTypeDefinition == null) {
return;
}
if (contentTypeDefinition.Parts.Any(part => part.PartDefinition.Name == typeof(ContainerPart).Name)) {
context.Builder.Weld<CustomContainerPart>();
}
}
}
3创建自定义部分驾驶员和使用这种显示方法:
protected override DriverResult Display(CustomContainerPart part, string displayType, dynamic shapeHelper) {
return ContentShape("Parts_Container_CustomContained",() => {
var containerPart = part.As<ContainerPart>();
// copy code from Orchard.Core/Containers/Drivers/ContainerPartDriver.cs here and tweak it to use the CustomContainerPart display type property
// ..
var listShape = shapeHelper.List();
listShape.AddRange(pageOfItems.Select(item => _contentManager.BuildDisplay(item, part.DisplayType))); // here use your custom part setting
// ..
});
}
4最后你r Placement.info:
<Place Parts_Container_Contained="-" />
<Match DisplayType="Detail">
<Place Parts_Container_CustomContained="Content:7.5"/>
</Match>
不错的想法,但有点太复杂,看我的答案我是如何解决它的。 – ViRuSTriNiTy