Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rendering zones before rendering layout #5436

Merged
merged 9 commits into from
Feb 6, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Fluid.Ast;
using Fluid.Tags;
using Microsoft.AspNetCore.Html;
using OrchardCore.DisplayManagement.Shapes;
using OrchardCore.Liquid.Ast;

namespace OrchardCore.DisplayManagement.Liquid.Tags
Expand All @@ -30,7 +31,7 @@ public override async ValueTask<Completion> WriteToAsync(TextWriter writer, Text
var required = arguments.HasNamed("required") && Convert.ToBoolean(arguments["required"].ToStringValue());
var zone = layout[name];

if (required && zone != null && zone.Items.Count == 0)
if (required && zone != null && zone is Shape && zone.Items.Count == 0)
{
throw new InvalidOperationException("Zone not found while invoking 'render_section': " + name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ public Task<IHtmlContent> RenderBodyAsync()

var zone = ThemeLayout[name];

if (required && zone != null && zone.Items.Count == 0)
if (required && zone != null && zone is Shape && zone.Items.Count == 0)
{
throw new InvalidOperationException("Zone not found: " + name);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using OrchardCore.DisplayManagement.Shapes;
using OrchardCore.DisplayManagement.Zones;

namespace OrchardCore.DisplayManagement.Theming
{
/// <summary>
/// This class represents a precompiled _Layout.cshtml view that renders a
/// This class represents a precompiled _Layout.cshtml view that renders a
/// Layout shape and the View's body in its Content zone.
///
///
/// 1- Views look for any _ViewStart.cshtml
/// 2- <see cref="ThemingViewsFeatureProvider"/> has registered <see cref="ThemeViewStart"/> as the top one
/// 3- <see cref="ThemeViewStart"/> then set a special Layout filename as the default View's Layout.
Expand All @@ -16,15 +20,35 @@ public class ThemeLayout : Razor.RazorPage<dynamic>
{
public override async Task ExecuteAsync()
{
// The View's body is rendered
// The View's body is rendered
var body = RenderLayoutBody();

if (ThemeLayout != null)
{
// Then is added to the Content zone of the Layout shape
ThemeLayout.Content.Add(body);

// Finally we render the Shape's HTML to the page's output
// Render Shapes in Content
if(ThemeLayout.Content is IShape content)
{
var htmlContent = await DisplayAsync(content);
ThemeLayout.Content = htmlContent;
}

if (ThemeLayout is ZoneHolding layout)
{
foreach (var zone in layout.Properties.ToArray())
{
if(zone.Value is IShape shape)
{
// Render each layout zone
var htmlZone = await DisplayAsync(shape);
layout.Properties[zone.Key] = htmlZone;
}
}
}

// Finally we render the Layout Shape's HTML to the page's output
ns8482e marked this conversation as resolved.
Show resolved Hide resolved
Write(await DisplayAsync(ThemeLayout));
}
else
Expand Down