Error executing template "Designs/Swift/Swift_Themes_Collection.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at CompiledRazorTemplates.Dynamic.RazorEngine_666879c1bdb042348788ca1a64ac85ce.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) in /_/src/Application/Providers/Dynamicweb.Rendering.Providers.NetCore/Razor/RazorTemplateRenderingProvider.cs:line 99
   at Dynamicweb.Rendering.TemplateRenderingService.Render(Template template) in E:\A10\_w\2\s\src\Core\Dynamicweb.Core\Rendering\TemplateRenderingService.cs:line 21
   at Dynamicweb.Rendering.Template.RenderRazorTemplate() in E:\A10\_w\2\s\src\Core\Dynamicweb.Core\Rendering\Template.cs:line 749

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.GetRawValueString("CustomHeaderInclude").Replace("/Files/Templates/Designs/Swift/", ""); 47 if (Model.Area.Item.GetFile("CustomHeaderInclude") != null) 48 { 49 customHeaderInclude = Model.Area.Item.GetFile("CustomHeaderInclude").Path.Replace("/Files/Templates/Designs/Swift/", ""); 50 } 51 52 string masterTheme = !string.IsNullOrWhiteSpace(Model.Area.Item.GetRawValueString("Theme")) ? " theme " + Model.Area.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 53 54 string favicon = Model.Area.Item.GetFile("Favicon") != null ? Model.Area.Item.GetFile("Favicon").Path : "/Files/Templates/Designs/Swift/Assets/Images/favicon.png"; 55 56 var brandingPage = Dynamicweb.Content.Services.Pages?.GetPage(brandingPageId) ?? null; 57 var themesParagraphLastChanged = Dynamicweb.Content.Services.Paragraphs.GetParagraphsByPageId(themePageId).OrderByDescending(p => p.Audit.LastModifiedAt).FirstOrDefault(); 58 var cssLastModified = brandingPage.Audit.LastModifiedAt > themesParagraphLastChanged.Audit.LastModifiedAt ? brandingPage.Audit.LastModifiedAt : themesParagraphLastChanged.Audit.LastModifiedAt; 59 60 var cssStyleFileInfo = new System.IO.FileInfo(Dynamicweb.Core.SystemInformation.MapPath("/Files/Templates/Designs/Swift/Assets/css/styles.css")); 61 var jsFileInfo = new System.IO.FileInfo(Dynamicweb.Core.SystemInformation.MapPath("/Files/Templates/Designs/Swift/Assets/js/scripts.js")); 62 63 string googleTagManagerID = Model.Area.Item.GetString("GoogleTagManagerID"); 64 string googleAnalyticsMeasurementID = Pageview.AreaSettings.GetString("GoogleAnalyticsMeasurementID"); 65 66 bool allowTracking = AllowTracking(); 67 68 // Schema.org details for PDP 69 string productId = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString.Get("ProductID")) ? Dynamicweb.Context.Current.Request.QueryString.Get("ProductID") : ""; 70 bool isProductDetailsPage = !string.IsNullOrEmpty(productId); 71 bool isArticlePage = Model.ItemType == "Swift_Article"; 72 string schemaOrgType = string.Empty; 73 74 if (isProductDetailsPage) 75 { 76 schemaOrgType = "itemscope=\"\" itemtype=\"https://schema.org/Product\""; 77 } 78 79 if (isArticlePage) 80 { 81 schemaOrgType = "itemscope=\"\" itemtype=\"https://schema.org/Article\""; 82 } 83 } 84 85 <!doctype html> 86 <html lang="@Pageview.Area.CultureInfo.TwoLetterISOLanguageName"> 87 <head> 88 <!-- @swiftVersion --> 89 @* Required meta tags *@ 90 <meta charset="utf-8"> 91 <meta name="viewport" content="height=device-height, width=device-width, initial-scale=1.0"> 92 <link rel="preload" href="/Files/Templates/Designs/Swift/Assets/css/styles.css?@cssStyleFileInfo.LastWriteTime.Ticks" as="style"> 93 <link rel="preload" href="/Files/Templates/Designs/Swift/Assets/js/scripts.js?@jsFileInfo.LastWriteTime.Ticks" as="script"> 94 95 <link rel="shortcut icon" href="@favicon"> 96 <link rel="apple-touch-icon" href="/Files/Templates/Designs/Swift/Assets/Images/logo_transparent.png"> 97 <meta http-equiv="X-UA-Compatible" content="ie=edge"> 98 <meta name="googlebot-news" content="nosnippet"> 99 100 @Model.MetaTags 101 102 <title>@Model.Title</title> 103 104 @* Bootstrap + Swift stylesheet *@ 105 <link href="/Files/Templates/Designs/Swift/Assets/css/styles.css?@cssStyleFileInfo.LastWriteTime.Ticks" rel="stylesheet" media="all" type="text/css"> 106 107 @if (disableWideBreakpoints != "disableBoth") 108 { 109 <style> 110 @@media ( min-width: 1600px ) { 111 .container-xxl, 112 .container-xl, 113 .container-lg, 114 .container-md, 115 .container-sm, 116 .container { 117 max-width: 1520px; 118 } 119 } 120 </style> 121 122 if (disableWideBreakpoints != "disableUltraWideOnly") 123 { 124 <style> 125 @@media ( min-width: 1920px ) { 126 .container-xxl, 127 .container-xl, 128 .container-lg, 129 .container-md, 130 .container-sm, 131 .container { 132 max-width: 1820px; 133 } 134 } 135 </style> 136 } 137 } 138 139 @* Branding and Themes min stylesheet *@ 140 <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"> 141 <script src="/Files/Templates/Designs/Swift/Assets/js/scripts.js?@jsFileInfo.LastWriteTime.Ticks"></script> 142 143 <script type="module"> 144 swift.Scroll.hideHeadersOnScroll(); 145 swift.Scroll.handleAlternativeTheme(); 146 147 //Only load if AOS 148 const aosColumns = document.querySelectorAll('[data-aos]'); 149 if (aosColumns.length > 0) { 150 swift.AssetLoader.Load('/Files/Templates/Designs/Swift/Assets/js/aos.js?@jsFileInfo.LastWriteTime.Ticks', 'js'); 151 document.addEventListener('load.swift.assetloader', function () { 152 AOS.init({ duration: 400, delay: 100, easing: 'ease-in-out', mirror: false, disable: window.matchMedia('(prefers-reduced-motion: reduce)') }); 153 }); 154 } 155 </script> 156 157 @* Google gtag method - always include even if it is not used for anything *@ 158 <script> 159 window.dataLayer = window.dataLayer || []; 160 function gtag() { dataLayer.push(arguments); } 161 </script> 162 @* Google tag manager *@ 163 @if (!string.IsNullOrWhiteSpace(googleTagManagerID)) 164 { 165 <script> 166 gtag('consent', 'default', { 167 'ad_storage': 'denied', 168 'ad_user_data': 'denied', 169 'ad_personalization': 'denied', 170 'analytics_storage': 'denied' 171 }); 172 </script> 173 <script> 174 (function (w, d, s, l, i) { 175 w[l] = w[l] || []; w[l].push({ 176 'gtm.start': 177 new Date().getTime(), event: 'gtm.js' 178 }); var f = d.getElementsByTagName(s)[0], 179 j = d.createElement(s), dl = l != 'dataLayer' ? '&l=' + l : ''; j.async = true; j.src = 180 'https://www.googletagmanager.com/gtm.js?id=' + i + dl; f.parentNode.insertBefore(j, f); 181 })(window, document, 'script', 'dataLayer', '@(googleTagManagerID)'); 182 </script> 183 if (allowTracking) 184 { 185 string adConsent = GetCookieOptInPermission("Marketing"); 186 string analyticsConsent = GetCookieOptInPermission("Statistical"); 187 <script> 188 gtag('consent', 'update', { 189 'ad_storage': '@adConsent', 190 'ad_user_data': '@adConsent', 191 'ad_personalization': '@adConsent', 192 'analytics_storage': '@analyticsConsent' 193 }); 194 </script> 195 } 196 } 197 198 @if (!string.IsNullOrWhiteSpace(googleAnalyticsMeasurementID) && allowTracking) 199 { 200 var GoogleAnalyticsDebugMode = ""; 201 202 if (Model.Area.Item.GetBoolean("EnableGoogleAnalyticsDebugMode")) 203 { 204 GoogleAnalyticsDebugMode = ", {'debug_mode': true}"; 205 } 206 207 <script async src="https://www.googletagmanager.com/gtag/js?id=@googleAnalyticsMeasurementID"></script> 208 <script> 209 gtag('js', new Date()); 210 gtag('config', '@googleAnalyticsMeasurementID'@GoogleAnalyticsDebugMode); 211 </script> 212 } 213 214 @if (!string.IsNullOrWhiteSpace(customHeaderInclude)) 215 { 216 @RenderPartial(customHeaderInclude) 217 } 218 </head> 219 220 <body class="brand @(masterTheme)"> 221 222 @* Google tag manager *@ 223 @if (!string.IsNullOrWhiteSpace(googleTagManagerID) && allowTracking) 224 { 225 <noscript> 226 <iframe src="https://www.googletagmanager.com/ns.html?id=@(googleTagManagerID)" 227 height="0" width="0" style="display:none;visibility:hidden"></iframe> 228 </noscript> 229 } 230 231 <div data-intersect></div> 232 233 <main id="content" @(schemaOrgType)> 234 @inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.PageViewModel> 235 236 <style> 237 .swift-checkered { 238 background-image: linear-gradient(45deg, #a7a9ac 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #a7a9ac 75%), linear-gradient(45deg, transparent 75%, #a7a9ac 75%), linear-gradient(45deg, #a7a9ac 25%, #bcbec0 25%); 239 background-size: 20px 20px; 240 background-position: 0 0, 0 0, -10px -10px, 10px 10px; 241 } 242 .theme-option { 243 border-radius: 2px; 244 padding: 0.5em; 245 } 246 </style> 247 248 @{ 249 string iconPath = "/Files/Templates/Designs/Swift/Assets/icons/"; 250 bool hasUsageData = Dynamicweb.Core.Converter.ToBoolean(Dynamicweb.Context.Current.Request["auditUsages"]); 251 string buttonLabel = hasUsageData ? "Refresh theme usages" : "Analyze usage of all themes"; 252 string urlPath = Dynamicweb.Frontend.SearchEngineFriendlyURLs.GetFriendlyUrl(Model.ID) + "?auditUsages=true"; 253 } 254 255 256 257 <div class="container my-5"> 258 <div class="grid gap-3 mb-3 pb-3 text-center border-bottom"> 259 <div class="g-col-12"> 260 <h1 class="h1">@Translate("Themes") </h1> 261 <div class="lead">@Translate("Take full control of all the colors")</div> 262 </div> 263 </div> 264 <div class="d-grid gap-2"> 265 <a href="@urlPath" class="btn btn-primary" role="button"> 266 @ReadFile(iconPath + "search.svg") 267 @buttonLabel 268 </a> 269 </div> 270 <div class="grid gap-3"> 271 @Model.Placeholder("content", "content", "default:true;sort:1") 272 </div> 273 </div> 274 275 <script> 276 function fallbackCopyTextToClipboard(text) { 277 var textArea = document.createElement("textarea"); 278 textArea.value = text; 279 280 // Avoid scrolling to bottom 281 textArea.style.top = "0"; 282 textArea.style.left = "0"; 283 textArea.style.position = "fixed"; 284 285 document.body.appendChild(textArea); 286 textArea.focus(); 287 textArea.select(); 288 289 try { 290 var successful = document.execCommand('copy'); 291 var msg = successful ? 'successful' : 'unsuccessful'; 292 console.log('Fallback: Copying text command was ' + msg); 293 } catch (err) { 294 console.error('Fallback: Oops, unable to copy', err); 295 } 296 297 document.body.removeChild(textArea); 298 } 299 function copyTextToClipboard(text) { 300 if (!navigator.clipboard) { 301 fallbackCopyTextToClipboard(text); 302 return; 303 } 304 navigator.clipboard.writeText(text).then(function () { 305 console.log('Async: Copying to clipboard was successful!'); 306 }, function (err) { 307 console.error('Async: Could not copy text: ', err); 308 }); 309 } 310 </script> 311 @{ 312 string cssPathEcommerceBadges = Dynamicweb.Context.Current.Server.MapPath($"/Files/Templates/Designs/Swift/_parsed/Swift_css/Swift_ecommerce_badge_styles_{Model.Area.ID}.css"); 313 string cssPathTheme = Dynamicweb.Context.Current.Server.MapPath($"/Files/Templates/Designs/Swift/_parsed/Swift_css/Swift_theme_styles_{Model.Area.ID}.css"); 314 string cssPathFont = Dynamicweb.Context.Current.Server.MapPath($"/Files/Templates/Designs/Swift/_parsed/Swift_css/Swift_font_styles_{Model.Area.ID}.css"); 315 string cssPathBranding = Dynamicweb.Context.Current.Server.MapPath($"/Files/Templates/Designs/Swift/_parsed/Swift_css/Swift_branding_styles_{Model.Area.ID}.css"); 316 string cssPathCss = Dynamicweb.Context.Current.Server.MapPath($"/Files/Templates/Designs/Swift/_parsed/Swift_css/Swift_css_styles_{Model.Area.ID}.css"); 317 string cssPathCombined = Dynamicweb.Context.Current.Server.MapPath($"/Files/Templates/Designs/Swift/_parsed/Swift_css/Swift_styles_{Model.Area.ID}.min.css"); 318 319 string tmpPath = Dynamicweb.Context.Current.Server.MapPath($"/Files/Templates/Designs/Swift/_parsed/Swift_css/Swift_theme_styles_{Model.Area.ID}.tmp"); 320 Dynamicweb.Core.Helpers.TextFileHelper.WriteTextFile(Dynamicweb.Core.Helpers.TextFileHelper.ReadTextFile(tmpPath), cssPathTheme, false); 321 System.IO.File.Delete(tmpPath); 322 323 string combinedCss = Dynamicweb.Core.Helpers.TextFileHelper.ReadTextFile(cssPathBranding); 324 combinedCss += Dynamicweb.Core.Helpers.TextFileHelper.ReadTextFile(cssPathTheme); 325 combinedCss += Dynamicweb.Core.Helpers.TextFileHelper.ReadTextFile(cssPathFont); 326 combinedCss += Dynamicweb.Core.Helpers.TextFileHelper.ReadTextFile(cssPathEcommerceBadges); 327 combinedCss += Dynamicweb.Core.Helpers.TextFileHelper.ReadTextFile(cssPathCss); 328 combinedCss = System.Text.RegularExpressions.Regex.Replace(combinedCss, @"\{([\s\S]*?)\}", match => 329 { 330 string content = match.Groups[1].Value; 331 content = System.Text.RegularExpressions.Regex.Replace(content, @"\s+", " "); // Collapse multiple spaces to a single space 332 return "{" + content.Trim() + "}"; 333 }); 334 combinedCss = System.Text.RegularExpressions.Regex.Replace(combinedCss, @"\t|\n|\r", ""); 335 combinedCss = combinedCss.Replace("\00a0", " "); //Re-insert spaces for content text 336 Dynamicweb.Core.Helpers.TextFileHelper.WriteTextFile(combinedCss, cssPathCombined, false); 337 } 338 339 </main> 340 341 @* Render any offcanvas menu here *@ 342 @RenderSnippet("offcanvas") 343 </body> 344 345 </html> 346