diff --git a/src/OrchardCore.Modules/OrchardCore.Admin/Startup.cs b/src/OrchardCore.Modules/OrchardCore.Admin/Startup.cs index 7d08f46eabb..fee003ba35f 100644 --- a/src/OrchardCore.Modules/OrchardCore.Admin/Startup.cs +++ b/src/OrchardCore.Modules/OrchardCore.Admin/Startup.cs @@ -1,4 +1,6 @@ using System; +using Fluid; +using Fluid.Values; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.ApplicationModels; @@ -9,10 +11,13 @@ using OrchardCore.Admin.Controllers; using OrchardCore.Admin.Drivers; using OrchardCore.Admin.Models; +using OrchardCore.DisplayManagement; using OrchardCore.DisplayManagement.Handlers; +using OrchardCore.DisplayManagement.ModelBinding; using OrchardCore.DisplayManagement.Theming; using OrchardCore.Environment.Shell.Configuration; using OrchardCore.Environment.Shell.Scope; +using OrchardCore.Liquid; using OrchardCore.Modules; using OrchardCore.Mvc.Core.Utilities; using OrchardCore.Mvc.Routing; @@ -93,4 +98,38 @@ public override void ConfigureServices(IServiceCollection services) services.AddSiteSettingsPropertyDeploymentStep(S => S["Admin settings"], S => S["Exports the admin settings."]); } } + + [RequireFeatures("OrchardCore.Liquid")] + public class LiquidStartup : StartupBase + { + public override void ConfigureServices(IServiceCollection services) + { + services.Configure(o => + { + o.Scope.SetValue(nameof(Navbar), new FunctionValue(async (args, ctx) => + { + if (ctx is LiquidTemplateContext context) + { + var displayManager = context.Services.GetRequiredService>(); + var updateModelAccessor = context.Services.GetRequiredService(); + + var shape = await displayManager.BuildDisplayAsync(updateModelAccessor.ModelUpdater); + + return FluidValue.Create(shape, ctx.Options); + } + + return NilValue.Instance; + })); + + o.MemberAccessStrategy.Register((navbar, name, context) => + { + return name switch + { + nameof(Navbar.Properties) => new ObjectValue(navbar.Properties), + _ => NilValue.Instance + }; + }); + }); + } + } } diff --git a/src/OrchardCore.Modules/OrchardCore.Admin/Views/Navbar.cshtml b/src/OrchardCore.Modules/OrchardCore.Admin/Views/Navbar.cshtml index 91b5f1d422d..81684dd717b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Admin/Views/Navbar.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Admin/Views/Navbar.cshtml @@ -1,6 +1,20 @@ +@using OrchardCore.Admin.Models +@using OrchardCore.DisplayManagement +@using OrchardCore.DisplayManagement.ModelBinding + +@inject IDisplayManager DisplayManager +@inject IUpdateModelAccessor UpdateModelAccessor + @if (Model.Content == null) { - return; + dynamic shape = await DisplayAsync(await DisplayManager.BuildDisplayAsync(UpdateModelAccessor.ModelUpdater, (string)Model.Metadata.DisplayType)); + + if (shape.Content == null) + { + return; + } + + Model.Content = shape.Content; }