mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Handling optional Content context of content part element rendering.
Content is optional context, so if it's null, we can't render the part element. This typically only happens when the layout editor is used outside the context of a content item and still renders the various content part elements as part of the toolbox.
This commit is contained in:
@@ -20,6 +20,12 @@ namespace Orchard.Layouts.Drivers {
|
||||
}
|
||||
|
||||
protected override void OnDisplaying(ContentPart element, ElementDisplayContext context) {
|
||||
// Content is optional context, so if it's null, we can't render the part element.
|
||||
// This typically only happens when the layout editor is used outside the context of
|
||||
// a content item and still renders the various content part elements as part of the toolbox.
|
||||
if (context.Content == null)
|
||||
return;
|
||||
|
||||
var contentItem = context.Content.ContentItem;
|
||||
var contentPartName = (string)element.Descriptor.StateBag["ElementTypeName"];
|
||||
var contentPart = contentItem.Parts.FirstOrDefault(x => x.PartDefinition.Name == contentPartName);
|
||||
|
@@ -1 +1,3 @@
|
||||
@Display(Model.Content)
|
||||
@if (Model.Content != null) {
|
||||
@Display(Model.Content)
|
||||
}
|
@@ -3,6 +3,8 @@
|
||||
@{
|
||||
var tagBuilder = TagBuilderExtensions.AddCommonElementAttributes(new OrchardTagBuilder("div"), Model);
|
||||
}
|
||||
@tagBuilder.StartElement
|
||||
@Display(Model.Content)
|
||||
@tagBuilder.EndElement
|
||||
@if (Model.Content != null) {
|
||||
@tagBuilder.StartElement
|
||||
@Display(Model.Content)
|
||||
@tagBuilder.EndElement
|
||||
}
|
Reference in New Issue
Block a user