Error executing template "Designs/Swift/Navigation/Nav_Sidenavigation_Custom.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
at CompiledRazorTemplates.Dynamic.RazorEngine_88ba3d83ab864892924340c43d5eecb2.Execute() in C:\inetpub\solutions\Goecker-2022-Prod\Files\Templates\Designs\Swift\Navigation\Nav_Sidenavigation_Custom.cshtml:line 18
at RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context, TextWriter reader)
at RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass16_0.<RunCompile>b__0(TextWriter writer)
at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
at Dynamicweb.Rendering.RazorTemplateRenderingProvider.Render(Template template)
at Dynamicweb.Rendering.TemplateRenderingService.Render(Template template)
at Dynamicweb.Rendering.Template.RenderRazorTemplate()
1 @inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.Navigation.NavigationTreeViewModel>
2 @using Dynamicweb.Core
3
4 @* CUSTOM TEMPLATE *@
5
6 @if (Model.Nodes.Any())
7 {
8 var theme = Model.Parameters.ContainsKey("Theme") ? Model.Parameters["Theme"].ToString().ToLower() : string.Empty;
9 var rootPageId = Model.Parameters.ContainsKey("RootpageId") ? Model.Parameters["RootpageId"].ToString().ToLower() : string.Empty;
10 bool mobileOrTablet = Pageview.Device == Dynamicweb.Frontend.Devices.DeviceType.Mobile || Pageview.Device == Dynamicweb.Frontend.Devices.DeviceType.Tablet;
11 var guid = Guid.NewGuid();
12
13 <button class="btn btn-secondary mb-3 @(mobileOrTablet ? "" : "hidden")" data-bs-toggle="collapse" data-bs-target="#sidenav-@guid">@Translate("Menu")</button>
14
15 <div class="sidenav border-1 d-flex flex-column @theme @(mobileOrTablet ? "collapse" : "")" id="sidenav-@guid">
16 @if (!string.IsNullOrWhiteSpace(rootPageId))
17 {
18 var rootPage = Dynamicweb.Services.Pages.GetPage(Converter.ToInt32(rootPageId));
19
20 <a class="sidenav-link border-1 border-bottom border-top py-2 ps-1 text-decoration-none link-primary fw-bold" href="/Default.aspx?ID=@rootPage.ID">@rootPage.GetDisplayName()</a>
21
22 if (Model.Nodes.Any())
23 {
24 <div class="subnav d-flex flex-column">
25 @foreach (var node in Model.Nodes)
26 {
27 @RenderNavigationLink(node)
28 }
29 </div>
30 }
31 }
32 </div>
33 }
34
35 @helper RenderNavigationLink(Dynamicweb.Frontend.Navigation.NavigationTreeNodeViewModel node)
36 {
37 var paddingStart = node.Level + 1;
38
39 <a class="sidenav-link border-1 border-bottom py-2 ps-@paddingStart @(node.IsActive ? "bg-light" : "") text-decoration-none link-primary" href="/Default.aspx?ID=@node.PageId">@node.Name</a>
40
41 if (node.Nodes.Any())
42 {
43 <div class="subnav d-flex flex-column">
44 @foreach (var childNode in node.Nodes)
45 {
46 @RenderNavigationLink(childNode)
47 }
48 </div>
49 }
50 }