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:
Sipke Schoorstra
2015-02-22 10:28:18 +01:00
parent 3f15163297
commit c0e46f2930
3 changed files with 14 additions and 4 deletions

View File

@@ -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);

View File

@@ -1 +1,3 @@
@Display(Model.Content)
@if (Model.Content != null) {
@Display(Model.Content)
}

View File

@@ -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
}