Error executing template "Designs/Hive/_parsed/Hive_PageCleanNoLayout.parsed.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at CompiledRazorTemplates.Dynamic.RazorEngine_b75780c1cf53486bb77a3f85fcdd6629.Execute() in C:\inetpub\wwwroot\directions2023\Files\Templates\Designs\Hive\_parsed\Hive_PageCleanNoLayout.parsed.cshtml:line 241
   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.PageViewModel> @using System @using Dynamicweb @using Dynamicweb.Environment @using Dynamicweb.Frontend @using System; @using System.Web; @{ //CUSTOM CODE //handle Maintenance mode var maintenancePage = Model.Area.Item?.GetLink("MaintenancePage") ?? null; bool maintenanceMode = Model.Area.Item.GetBoolean("MaintenanceMode"); DateTime maintenanceStartDate = Model.Area.Item.GetDateTime("MaintenanceStartDate"); DateTime maintenanceEndDate = Model.Area.Item.GetDateTime("MaintenanceEndDate"); DateTime currentDate = System.DateTime.Now; maintenanceMode = maintenanceMode && maintenanceStartDate <= currentDate && maintenanceEndDate >= currentDate; var adminUser = Dynamicweb.Security.UserManagement.User.GetCurrentBackendUser(); int currentPage = Dynamicweb.Frontend.PageView.Current().Page.ID; if(maintenanceMode && maintenancePage != null && adminUser == null && maintenancePage.PageId != currentPage) { string redirectLink = "/" + maintenancePage; HttpContext.Current.Response.Redirect(redirectLink); } int signInPageId = GetPageIdByNavigationTag("SignInPage"); int currentPageId = Pageview.Page.ID; string signInTemplateCssClass = currentPageId == signInPageId ? "signup-template overflow-md-hidden" : string.Empty; string signInPaddingCssClass = currentPageId == signInPageId ? string.Empty : "ps-sm-5 ps-md-0"; } @functions { string GetCookieOptInPermission(string category) { bool categoryOrAllGranted = false; if (CookieManager.IsCookieManagementActive) { var cookieOptInLevel = CookieManager.GetCookieOptInLevel(); var cookieOptInCategories = CookieManager.GetCookieOptInCategories(); categoryOrAllGranted = cookieOptInCategories.Contains(category) || cookieOptInLevel == CookieOptInLevel.All; } return categoryOrAllGranted ? "granted" : "denied"; } bool AllowTracking() { bool allowTracking = true; if (CookieManager.IsCookieManagementActive) { var cookieOptInLevel = CookieManager.GetCookieOptInLevel(); var cookieOptInCategories = CookieManager.GetCookieOptInCategories(); bool consentEither = (cookieOptInCategories.Contains("Statistical") || cookieOptInCategories.Contains("Marketing")); bool consentFunctional = cookieOptInLevel == CookieOptInLevel.Functional; bool consentAtLeastOne = cookieOptInLevel == CookieOptInLevel.All || (consentFunctional && consentEither); allowTracking = consentAtLeastOne; } return allowTracking; } } @{ bool renderAsResponsive = Model.Area.Item.GetString("DeviceRendering", "responsive").Equals("responsive", StringComparison.OrdinalIgnoreCase); bool renderMobile = Pageview.Device == Dynamicweb.Frontend.Devices.DeviceType.Mobile || Pageview.Device == Dynamicweb.Frontend.Devices.DeviceType.Tablet; string responsiveClassDesktop = string.Empty; string responsiveClassMobile = string.Empty; if (renderAsResponsive) { responsiveClassDesktop = " d-none d-xl-block"; responsiveClassMobile = " d-block d-xl-none"; } string favicon = Model.Area.Item.GetRawValueString("Favicon", "/Files/Templates/Designs/Hive/Assets/Images/favicon.png"); string appleTouchIcon = Model.Area.Item.GetRawValueString("AppleTouchIcon", "/Files/Templates/Designs/Hive/Assets/Images/apple-touch-icon.png"); string headerCssClass = "sticky-top"; bool movePageBehind = false; if (Model.PropertyItem != null) { headerCssClass = Model.PropertyItem.GetRawValueString("MoveThisPageBehindTheHeader", "sticky-top"); movePageBehind = headerCssClass == "fixed-top" && !Pageview.IsVisualEditorMode ? true : false; } headerCssClass = headerCssClass == "" ? "sticky-top" : headerCssClass; headerCssClass = Pageview.IsVisualEditorMode ? "" : headerCssClass; string googleTagManagerID = Model.Area.Item.GetString("GoogleTagManagerID").Trim(); string googleAnalyticsMeasurementID = Model.Area.Item.GetString("GoogleAnalyticsMeasurementID").Trim(); bool allowTracking = AllowTracking(); SetMetaTags(); Uri url = Dynamicweb.Context.Current.Request.Url; string hostName = url.Host; var cssStyleFileInfo = new System.IO.FileInfo(Dynamicweb.Core.SystemInformation.MapPath("/Files/Templates/Designs/Swift/Assets/css/styles.css")); var jsFileInfo = new System.IO.FileInfo(Dynamicweb.Core.SystemInformation.MapPath("/Files/Templates/Designs/Swift/Assets/js/scripts.js")); //CUSTOM CODE// var customJsFileInfo = new System.IO.FileInfo(Dynamicweb.Core.SystemInformation.MapPath("Files/Templates/Designs/Swift/Assets/js/custom-scripts.js")); //CUSTOM CODE// Dynamicweb.Context.Current.Response.AddHeader("link", $"</Files/Templates/Designs/Swift/Assets/css/styles.css?{cssStyleFileInfo.LastWriteTime.Ticks}>; rel=preload; as=style;"); Dynamicweb.Context.Current.Response.AddHeader("link", $"</Files/Templates/Designs/Swift/Assets/js/scripts.js?{jsFileInfo.LastWriteTime.Ticks}>; rel=preload; as=script;"); Dynamicweb.Context.Current.Response.AddHeader("link", $"</Files/Templates/Designs/Swift/Assets/js/custom-scripts.js?{customJsFileInfo.LastWriteTime.Ticks}>; rel=preload; as=script;"); <!doctype html> <html lang="@Pageview.Area.CultureInfo.TwoLetterISOLanguageName"> <head> @* Required meta tags *@ <meta charset="utf-8"> <meta name="viewport" content="height=device-height, width=device-width, initial-scale=1.0"> <link rel="shortcut icon" href="@favicon"> <link rel="apple-touch-icon" href="@appleTouchIcon"> @Model.MetaTags <title>@Model.Title</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous"> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <script src="https://kit.fontawesome.com/8a6abf00c3.js" crossorigin="anonymous"></script> <link rel="stylesheet" href="/Files/Templates/Designs/Hive/Assets/css/theme.min.css" /> <link rel="stylesheet" crossorigin href="/Files/Templates/Designs/Hive/Assets/css/custom.css" /> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/slim-select/2.6.0/slimselect.css" integrity="sha512-ijXMfMV6D0xH0UfHpPnqrwbw9cjd4AbjtWbdfVd204tXEtJtvL3TTNztvqqr9AbLcCiuNTvqHL5c9v2hOjdjpA==" crossorigin="anonymous" referrerpolicy="no-referrer" /> <script type="module" crossorigin src="/Files/Templates/Designs/Hive/Assets/js/scripts.js"></script> <script type="module" crossorigin src="/Files/Templates/Designs/Hive/Assets/js/custom-scripts.js?@customJsFileInfo.LastWriteTime.Ticks"></script> <script async src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDb4ipgUwo0RwfQuQ_jJ1W4__kc0Osij70&loading=async&callback=initMap"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/slim-select/2.6.0/slimselect.min.js" integrity="sha512-0E8oaoA2v32h26IycsmRDShtQ8kMgD91zWVBxdIvUCjU3xBw81PV61QBsBqNQpWkp/zYJZip8Ag3ifmzz1wCKQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/gmaps-marker-clusterer/1.2.2/markerclusterer.js" integrity="sha512-RF20m+3oGAUZDP/8GLmh5Jekk1WW7KCjBphNiNy4ximKZWgOOK2e2yHZ9fTd50tbSUzgOTXYsF92EmK4idhCsg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script> @* Google gtag method - always include even if it is not used for anything *@ <script> window.dataLayer = window.dataLayer || []; function gtag() { dataLayer.push(arguments); } </script> @* Google tag manager *@ @if (!string.IsNullOrWhiteSpace(googleTagManagerID)) { <script> gtag('consent', 'default', { 'ad_storage': 'denied', 'ad_user_data': 'denied', 'ad_personalization': 'denied', 'analytics_storage': 'denied' }); </script> <script> (function (w, d, s, l, i) { w[l] = w[l] || []; w[l].push({ 'gtm.start': new Date().getTime(), event: 'gtm.js' }); var f = d.getElementsByTagName(s)[0], j = d.createElement(s), dl = l != 'dataLayer' ? '&l=' + l : ''; j.async = true; j.src = 'https://www.googletagmanager.com/gtm.js?id=' + i + dl; f.parentNode.insertBefore(j, f); })(window, document, 'script', 'dataLayer', '@(googleTagManagerID)'); </script> if (allowTracking) { string adConsent = GetCookieOptInPermission("Marketing"); string analyticsConsent = GetCookieOptInPermission("Statistical"); <script> gtag('consent', 'update', { 'ad_storage': '@adConsent', 'ad_user_data': '@adConsent', 'ad_personalization': '@adConsent', 'analytics_storage': '@analyticsConsent' }); </script> } } @if (!string.IsNullOrWhiteSpace(googleAnalyticsMeasurementID) && allowTracking) { var GoogleAnalyticsDebugMode = ""; if (Model.Area.Item.GetBoolean("EnableGoogleAnalyticsDebugMode")) { GoogleAnalyticsDebugMode = ", {'debug_mode': true}"; } <script async src="https://www.googletagmanager.com/gtag/js?id=@googleAnalyticsMeasurementID"></script> <script> gtag('js', new Date()); gtag('config', '@googleAnalyticsMeasurementID'@GoogleAnalyticsDebugMode); </script> } </head> <body class="brand bg-gray-100 @signInTemplateCssClass" id="page@(Model.ID)"> @* Google tag manager *@ @if (!string.IsNullOrWhiteSpace(googleTagManagerID) && allowTracking) { <noscript> <iframe src="https://www.googletagmanager.com/ns.html?id=@(googleTagManagerID)" height="0" width="0" style="display:none;visibility:hidden"></iframe> </noscript> } <main class="content" id="content"> <div class="g-col-12 @signInPaddingCssClass content-container"> @inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.PageViewModel> @using System @using Dynamicweb.Ecommerce.ProductCatalog @{ string theme = ""; string gridContent = ""; if (Model.PropertyItem != null) { theme = !string.IsNullOrWhiteSpace(Model.PropertyItem.GetRawValueString("Theme")) ? " theme " + Model.PropertyItem.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; } if (Model.Item != null) { gridContent = Model.Grid("Grid", "Grid", "default:true;sort:1", "HivePage"); } bool doNotRenderPage = false; //Render the page if (!doNotRenderPage) { { <div class="item_@Model.Item.SystemName.ToLower()"> @gridContent </div> } } if (!Model.IsCurrentUserAllowed) { int signInPage = GetPageIdByNavigationTag("SignInPage"); int dashboardPage = GetPageIdByNavigationTag("MyAccountDashboardPage"); if (!Pageview.IsVisualEditorMode) { if (signInPage != 0) { if (signInPage != Model.ID) { Dynamicweb.Context.Current.Response.Redirect("/Default.aspx?ID=" + signInPage); } else { if (dashboardPage != 0) { Dynamicweb.Context.Current.Response.Redirect("/Default.aspx?ID=" + dashboardPage); } else { Dynamicweb.Context.Current.Response.Redirect("/"); } } } else { <div class="alert alert-dark m-0" role="alert"> <span>@Translate("You do not have access to this page")</span> </div> } } else { <div class="alert alert-dark m-0" role="alert"> <span>@Translate("To work on this page, you must be signed in, in the frontend")</span> </div> } } } </div> </main> </body> </html> } @functions { void SetMetaTags() { //Verification Tokens string siteVerificationGoogle = Model.Area.Item.GetString("Google_Site_Verification") != null ? Model.Area.Item.GetString("Google_Site_Verification") : ""; //Generic Site Values string openGraphFacebookAppID = Model.Area.Item.GetString("Fb_app_id") != null ? Model.Area.Item.GetString("Fb_app_id") : ""; string openGraphType = Model.Area.Item.GetString("Open_Graph_Type") != null ? Model.Area.Item.GetString("Open_Graph_Type") : ""; string openGraphSiteName = Model.Area.Item.GetString("Open_Graph_Site_Name") != null ? Model.Area.Item.GetString("Open_Graph_Site_Name") : ""; string twitterCardSite = Model.Area.Item.GetString("Twitter_Site") != null ? Model.Area.Item.GetString("Twitter_Site") : ""; //Page specific values string openGraphSiteTitle = Model.Area.Item.GetString("Open_Graph_Title") != null ? Model.Area.Item.GetString("Open_Graph_Title") : ""; FileViewModel openGraphImage = Model.Area.Item.GetFile("Open_Graph_Image"); string openGraphImageALT = Model.Area.Item.GetString("Open_Graph_Image_ALT") != null ? Model.Area.Item.GetString("Open_Graph_Image_ALT") : ""; string openGraphDescription = Model.Area.Item.GetString("Open_Graph_Description") != null ? Model.Area.Item.GetString("Open_Graph_Description") : ""; string twitterCardURL = Model.Area.Item.GetString("Twitter_URL") != null ? Model.Area.Item.GetString("Twitter_URL") : ""; string twitterCardTitle = Model.Area.Item.GetString("Twitter_Title") != null ? Model.Area.Item.GetString("Twitter_Title") : ""; string twitterCardDescription = Model.Area.Item.GetString("Twitter_Description") != null ? Model.Area.Item.GetString("Twitter_Description") : ""; FileViewModel twitterCardImage = Model.Area.Item.GetFile("Twitter_Image"); string twitterCardImageALT = Model.Area.Item.GetString("Twitter_Image_ALT") != null ? Model.Area.Item.GetString("Twitter_Image_ALT") : ""; string topImage = Pageview.Page.TopImage.StartsWith("/Files", StringComparison.OrdinalIgnoreCase) ? Pageview.Page.TopImage : $"/Files{Pageview.Page.TopImage}"; if (string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString["ProductID"])) { if (!string.IsNullOrEmpty(Model.Description)) { Pageview.Meta.AddTag($"<meta property=\"og:description\" content=\"{Model.Description}\">"); } else { Pageview.Meta.AddTag($"<meta property=\"og:description\" content=\"{openGraphDescription}\">"); } if (!string.IsNullOrEmpty(Pageview.Page.TopImage)) { Pageview.Meta.AddTag($"<meta property=\"og:image\" content=\"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}{topImage}\">"); Pageview.Meta.AddTag($"<meta property=\"og:image:secure_url\" content=\"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}{topImage}\">"); } else if (openGraphImage != null) { Pageview.Meta.AddTag($"<meta property=\"og:image\" content=\"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}{openGraphImage.Path}\">"); Pageview.Meta.AddTag($"<meta property=\"og:image:secure_url\" content=\"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}{openGraphImage.Path}\">"); } if (!string.IsNullOrEmpty(openGraphImageALT)) { Pageview.Meta.AddTag($"<meta property=\"og:image:alt\" content=\"{openGraphImageALT}\">"); } if (!string.IsNullOrEmpty(twitterCardDescription)) { Pageview.Meta.AddTag("twitter:description", twitterCardDescription); } if (!string.IsNullOrEmpty(Pageview.Page.TopImage)) { Pageview.Meta.AddTag("twitter:image", $"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}{topImage}"); } else if (twitterCardImage != null) { Pageview.Meta.AddTag("twitter:image", $"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}{openGraphImage.Path}"); } if (!string.IsNullOrEmpty(twitterCardImageALT)) { Pageview.Meta.AddTag("twitter:image:alt", twitterCardImageALT); } } if (!string.IsNullOrEmpty(siteVerificationGoogle)) { Pageview.Meta.AddTag("google-site-verification", siteVerificationGoogle); } if (!string.IsNullOrEmpty(openGraphFacebookAppID)) { Pageview.Meta.AddTag($"<meta property=\"fb:app_id\" content=\"{openGraphFacebookAppID}\">"); } if (!string.IsNullOrEmpty(openGraphType)) { Pageview.Meta.AddTag($"<meta property=\"og:type\" content=\"{openGraphType}\">"); } if (!string.IsNullOrEmpty(openGraphSiteName)) { Pageview.Meta.AddTag($"<meta property=\"og:url\" content=\"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}{Pageview.SearchFriendlyUrl}\">"); } if (!string.IsNullOrEmpty(openGraphSiteName)) { Pageview.Meta.AddTag($"<meta property=\"og:site_name\" content=\"{openGraphSiteName}\">"); } if (!string.IsNullOrEmpty(Model.Title)) { Pageview.Meta.AddTag($"<meta property=\"og:title\" content=\"{Model.Title}\">"); } else { Pageview.Meta.AddTag($"<meta property=\"og:title\" content=\"{openGraphSiteTitle}\">"); } if (!string.IsNullOrEmpty(twitterCardSite)) { Pageview.Meta.AddTag("twitter:site", twitterCardSite); } if (!string.IsNullOrEmpty(twitterCardURL)) { Pageview.Meta.AddTag("twitter:url", twitterCardURL); } if (!string.IsNullOrEmpty(twitterCardTitle)) { Pageview.Meta.AddTag("twitter:title", twitterCardTitle); } } }