Error executing template "Designs/Swift/CPQ_PageNoLayout.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at DW_CPQ_API.ModelController..ctor(String modelVersionId, Nullable`1 pageId, NameValueCollection requestVars)
   at DW_CPQ_API.ModelController..ctor(Int32 pageId, NameValueCollection requestVars)
   at CompiledRazorTemplates.Dynamic.RazorEngine_c2eb65fb06db4e1fb6a4694148adb918.ExecuteAsync()
   at RazorEngine.Templating.TemplateBase.Run(ExecuteContext context, TextWriter reader)
   at RazorEngine.Templating.RazorEngineCore.RunTemplate(ICompiledTemplate template, TextWriter writer, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineService.Run(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.DynamicWrapperService.Run(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineServiceExtensions.Run(IRazorEngineService service, String name, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass23_0.<Run>b__0(TextWriter writer)
   at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
   at RazorEngine.Templating.RazorEngineServiceExtensions.Run(IRazorEngineService service, String name, Type modelType, Object model, DynamicViewBag viewBag)
   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> 2 @using Dynamicweb 3 @using Dynamicweb.Environment 4 5 @functions { 6 string GetCookieOptInPermission(string category) 7 { 8 bool categoryOrAllGranted = false; 9 10 if (CookieManager.IsCookieManagementActive) 11 { 12 var cookieOptInLevel = CookieManager.GetCookieOptInLevel(); 13 var cookieOptInCategories = CookieManager.GetCookieOptInCategories(); 14 categoryOrAllGranted = cookieOptInCategories.Contains(category) || cookieOptInLevel == CookieOptInLevel.All; 15 } 16 17 return categoryOrAllGranted ? "granted" : "denied"; 18 } 19 20 bool AllowTracking() 21 { 22 bool allowTracking = true; 23 if (CookieManager.IsCookieManagementActive) 24 { 25 var cookieOptInLevel = CookieManager.GetCookieOptInLevel(); 26 var cookieOptInCategories = CookieManager.GetCookieOptInCategories(); 27 28 bool consentEither = (cookieOptInCategories.Contains("Statistical") || cookieOptInCategories.Contains("Marketing")); 29 bool consentFunctional = cookieOptInLevel == CookieOptInLevel.Functional; 30 bool consentAtLeastOne = cookieOptInLevel == CookieOptInLevel.All || (consentFunctional && consentEither); 31 32 allowTracking = consentAtLeastOne; 33 } 34 return allowTracking; 35 } 36 } 37 38 @{ 39 string swiftVersion = ReadFile("/Files/Templates/Designs/Swift/swift_version.txt"); 40 @* Branding Themes Fonts *@ 41 var brandingPageId = Model.Area.Item.GetLink("BrandingPage") != null ? Model.Area.Item.GetLink("BrandingPage").PageId : 0; 42 var themePageId = Model.Area.Item.GetLink("ThemesPage") != null ? Model.Area.Item.GetLink("ThemesPage").PageId : 0; 43 44 var disableWideBreakpoints = Model.Area?.Item?.GetRawValueString("DisableWideBreakpoints", "default"); 45 46 string customHeaderInclude = Model.Area.Item.GetFile("CustomHeaderInclude") != null ? Model.Area.Item.GetFile("CustomHeaderInclude").Name : string.Empty; 47 48 string masterTheme = !string.IsNullOrWhiteSpace(Model.Area.Item.GetRawValueString("Theme")) ? " theme " + Model.Area.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 49 50 string favicon = Model.Area.Item.GetFile("Favicon") != null ? Model.Area.Item.GetFile("Favicon").Path : "/Files/Templates/Designs/Swift/Assets/Images/favicon.png"; 51 52 var brandingPage = Dynamicweb.Content.Services.Pages?.GetPage(brandingPageId) ?? null; 53 var themesParagraphLastChanged = Dynamicweb.Content.Services.Paragraphs.GetParagraphsByPageId(themePageId).OrderByDescending(p => p.Audit.LastModifiedAt).FirstOrDefault(); 54 var cssLastModified = brandingPage.Audit.LastModifiedAt > themesParagraphLastChanged.Audit.LastModifiedAt ? brandingPage.Audit.LastModifiedAt : themesParagraphLastChanged.Audit.LastModifiedAt; 55 56 var cssStyleFileInfo = new System.IO.FileInfo(Dynamicweb.Core.SystemInformation.MapPath("/Files/Templates/Designs/Swift/Assets/css/styles.css")); 57 var jsFileInfo = new System.IO.FileInfo(Dynamicweb.Core.SystemInformation.MapPath("/Files/Templates/Designs/Swift/Assets/js/scripts.js")); 58 59 string googleTagManagerID = Model.Area.Item.GetString("GoogleTagManagerID"); 60 string googleAnalyticsMeasurementID = Pageview.AreaSettings.GetString("GoogleAnalyticsMeasurementID"); 61 62 bool allowTracking = AllowTracking(); 63 64 // Schema.org details for PDP 65 string productId = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString.Get("ProductID")) ? Dynamicweb.Context.Current.Request.QueryString.Get("ProductID") : ""; 66 bool isProductDetailsPage = !string.IsNullOrEmpty(productId); 67 bool isArticlePage = Model.ItemType == "Swift_Article"; 68 string schemaOrgType = string.Empty; 69 70 if (isProductDetailsPage) 71 { 72 schemaOrgType = "itemscope=\"\" itemtype=\"https://schema.org/Product\""; 73 } 74 75 if (isArticlePage) 76 { 77 schemaOrgType = "itemscope=\"\" itemtype=\"https://schema.org/Article\""; 78 } 79 } 80 81 <!doctype html> 82 <html lang="@Pageview.Area.CultureInfo.TwoLetterISOLanguageName"> 83 <head> 84 <!-- @swiftVersion --> 85 @* Required meta tags *@ 86 <meta charset="utf-8"> 87 <meta name="viewport" content="height=device-height, width=device-width, initial-scale=1.0"> 88 <link rel="preload" href="/Files/Templates/Designs/Swift/Assets/css/styles.css?@cssStyleFileInfo.LastWriteTime.Ticks" as="style"> 89 <link rel="preload" href="/Files/Templates/Designs/Swift/Assets/js/scripts.js?@jsFileInfo.LastWriteTime.Ticks" as="script"> 90 91 <link rel="shortcut icon" href="@favicon"> 92 <link rel="apple-touch-icon" href="/Files/Templates/Designs/Swift/Assets/Images/logo_transparent.png"> 93 <meta http-equiv="X-UA-Compatible" content="ie=edge"> 94 <meta name="googlebot-news" content="nosnippet"> 95 96 @Model.MetaTags 97 98 <title>@Model.Title</title> 99 100 @* Bootstrap + Swift stylesheet *@ 101 <link href="/Files/Templates/Designs/Swift/Assets/css/styles.css?@cssStyleFileInfo.LastWriteTime.Ticks" rel="stylesheet" media="all" type="text/css"> 102 103 @if (disableWideBreakpoints != "disableBoth") 104 { 105 <style> 106 @@media ( min-width: 1600px ) { 107 .container-xxl, 108 .container-xl, 109 .container-lg, 110 .container-md, 111 .container-sm, 112 .container { 113 max-width: 1520px; 114 } 115 } 116 </style> 117 118 if (disableWideBreakpoints != "disableUltraWideOnly") 119 { 120 <style> 121 @@media ( min-width: 1920px ) { 122 .container-xxl, 123 .container-xl, 124 .container-lg, 125 .container-md, 126 .container-sm, 127 .container { 128 max-width: 1820px; 129 } 130 } 131 </style> 132 } 133 } 134 135 @* Branding and Themes min stylesheet *@ 136 <script type="importmap"> 137 { 138 "imports": { 139 "three": "https://cdn.jsdelivr.net/npm/three@v0.149.0/build/three.module.js", 140 "three/addons/": "https://cdn.jsdelivr.net/npm/three@v0.149.0/examples/jsm/" 141 } 142 } 143 </script> 144 <link href="/Files/Templates/Designs/Swift/_parsed/Swift_css/Swift_styles_@(Model.Area.ID).min.css?@cssLastModified.Ticks" rel="stylesheet" media="all" type="text/css" data-last-modified-content="@cssLastModified"> 145 <script src="/Files/Templates/Designs/Swift/Assets/js/scripts.js?@jsFileInfo.LastWriteTime.Ticks"></script> 146 147 <script type="module"> 148 swift.Scroll.hideHeadersOnScroll(); 149 swift.Scroll.handleAlternativeTheme(); 150 151 //Only load if AOS 152 const aosColumns = document.querySelectorAll('[data-aos]'); 153 if (aosColumns.length > 0) { 154 swift.AssetLoader.Load('/Files/Templates/Designs/Swift/Assets/js/aos.js?@jsFileInfo.LastWriteTime.Ticks', 'js'); 155 document.addEventListener('load.swift.assetloader', function () { 156 AOS.init({ duration: 400, delay: 100, easing: 'ease-in-out', mirror: false, disable: window.matchMedia('(prefers-reduced-motion: reduce)') }); 157 }); 158 } 159 </script> 160 161 @* Google gtag method - always include even if it is not used for anything *@ 162 <script> 163 window.dataLayer = window.dataLayer || []; 164 function gtag() { dataLayer.push(arguments); } 165 </script> 166 @* Google tag manager *@ 167 @if (!string.IsNullOrWhiteSpace(googleTagManagerID)) 168 { 169 <script> 170 gtag('consent', 'default', { 171 'ad_storage': 'denied', 172 'ad_user_data': 'denied', 173 'ad_personalization': 'denied', 174 'analytics_storage': 'denied' 175 }); 176 </script> 177 <script> 178 (function (w, d, s, l, i) { 179 w[l] = w[l] || []; w[l].push({ 180 'gtm.start': 181 new Date().getTime(), event: 'gtm.js' 182 }); var f = d.getElementsByTagName(s)[0], 183 j = d.createElement(s), dl = l != 'dataLayer' ? '&l=' + l : ''; j.async = true; j.src = 184 'https://www.googletagmanager.com/gtm.js?id=' + i + dl; f.parentNode.insertBefore(j, f); 185 })(window, document, 'script', 'dataLayer', '@(googleTagManagerID)'); 186 </script> 187 if (allowTracking) 188 { 189 string adConsent = GetCookieOptInPermission("Marketing"); 190 string analyticsConsent = GetCookieOptInPermission("Statistical"); 191 <script> 192 gtag('consent', 'update', { 193 'ad_storage': '@adConsent', 194 'ad_user_data': '@adConsent', 195 'ad_personalization': '@adConsent', 196 'analytics_storage': '@analyticsConsent' 197 }); 198 </script> 199 } 200 } 201 202 @if (!string.IsNullOrWhiteSpace(googleAnalyticsMeasurementID) && allowTracking) 203 { 204 var GoogleAnalyticsDebugMode = ""; 205 206 if (Model.Area.Item.GetBoolean("EnableGoogleAnalyticsDebugMode")) 207 { 208 GoogleAnalyticsDebugMode = ", {'debug_mode': true}"; 209 } 210 211 <script async src="https://www.googletagmanager.com/gtag/js?id=@googleAnalyticsMeasurementID"></script> 212 <script> 213 gtag('js', new Date()); 214 gtag('config', '@googleAnalyticsMeasurementID'@GoogleAnalyticsDebugMode); 215 </script> 216 } 217 218 @if (!string.IsNullOrWhiteSpace(customHeaderInclude)) 219 { 220 @RenderPartial($"Components/Custom/{customHeaderInclude}") 221 } 222 </head> 223 224 <body class="brand @(masterTheme)"> 225 226 @* Google tag manager *@ 227 @if (!string.IsNullOrWhiteSpace(googleTagManagerID) && allowTracking) 228 { 229 <noscript> 230 <iframe src="https://www.googletagmanager.com/ns.html?id=@(googleTagManagerID)" 231 height="0" width="0" style="display:none;visibility:hidden"></iframe> 232 </noscript> 233 } 234 235 <div data-intersect></div> 236 237 <main id="content" @(schemaOrgType)> 238 @inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.PageViewModel> 239 @using System 240 @using Dynamicweb.Ecommerce.ProductCatalog 241 @using DW_CPQ_API 242 243 244 <style> 245 body { 246 margin: 0; 247 padding: 0; 248 font-family: Arial, sans-serif; 249 } 250 .banner { 251 background-color: #3498db; /* nice blue color */ 252 color: #fff; /* white text color */ 253 padding: 20px; 254 text-align: center; 255 } 256 </style> 257 258 @{ 259 ModelController modelController = new ModelController(Pageview.Page.ID, Dynamicweb.Context.Current.Request.Params); 260 //Dynamicweb.Context.Current.Session["ModelController"] = modelController; 261 <input type="hidden" id="model_version_id" value="@(modelController.ModelVersionId)" /> 262 263 string theme = ""; 264 string gridContent = ""; 265 266 if (Model.PropertyItem != null) 267 { 268 theme = !string.IsNullOrWhiteSpace(Model.PropertyItem.GetRawValueString("Theme")) ? " theme " + Model.PropertyItem.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : "alert-dark"; 269 } 270 271 if (Model.Item != null) 272 { 273 gridContent = Model.Grid("Grid", "Grid", "default:true;sort:1", "Page"); 274 } 275 276 bool doNotRenderPage = false; 277 278 //Check if we are on the poduct detail page, and if there is data to render 279 ProductViewModel product = new ProductViewModel(); 280 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 281 { 282 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 283 if (string.IsNullOrEmpty(product.Id)) 284 { 285 doNotRenderPage = true; 286 } 287 } 288 289 <div class="alert @theme text-center"> 290 <h1>@Model.Title</h1> 291 </div> 292 293 //Render the page 294 if (!doNotRenderPage) 295 { 296 string itemIdentifier = Model?.Item?.SystemName != null ? "item_" + Model.Item.SystemName.ToLower() : "item_Swift_Page"; 297 298 <div class="item_@itemIdentifier"> 299 @gridContent 300 </div> 301 302 } 303 else 304 { 305 <div class="container"> 306 <div class="alert alert-info" role="alert">@Translate("Sorry. There is nothing to view here")</div> 307 </div> 308 } 309 310 if (!Model.IsCurrentUserAllowed) 311 { 312 int signInPage = GetPageIdByNavigationTag("SignInPage"); 313 int dashboardPage = GetPageIdByNavigationTag("MyAccountDashboardPage"); 314 315 if (!Pageview.IsVisualEditorMode) 316 { 317 if (signInPage != 0) 318 { 319 if (signInPage != Model.ID) 320 { 321 Dynamicweb.Context.Current.Response.Redirect("/Default.aspx?ID=" + signInPage); 322 } 323 else 324 { 325 if (dashboardPage != 0) 326 { 327 Dynamicweb.Context.Current.Response.Redirect("/Default.aspx?ID=" + dashboardPage); 328 } 329 else 330 { 331 Dynamicweb.Context.Current.Response.Redirect("/"); 332 } 333 } 334 } 335 else 336 { 337 <div class="alert alert-dark m-0" role="alert"> 338 <span>@Translate("You do not have access to this page")</span> 339 </div> 340 } 341 } 342 else 343 { 344 <div class="alert m-0" role="alert"> 345 <span>@Translate("To work on this page, you must be signed in, in the frontend")</span> 346 </div> 347 } 348 } 349 } 350 351 </main> 352 353 @* Render any offcanvas menu here *@ 354 @RenderSnippet("offcanvas") 355 </body> 356 357 </html> 358