Error executing template "Designs/Swift/Swift_Page.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at CompiledRazorTemplates.Dynamic.RazorEngine_3e96e981ee4f4dd9b7eea76ebf26541d.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 System 3 @using Dynamicweb 4 @using Dynamicweb.Environment 5 @using Dynamicweb.Frontend 6 7 @functions { 8 string GetCookieOptInPermission(string category) 9 { 10 bool categoryOrAllGranted = false; 11 12 if (CookieManager.IsCookieManagementActive) 13 { 14 var cookieOptInLevel = CookieManager.GetCookieOptInLevel(); 15 var cookieOptInCategories = CookieManager.GetCookieOptInCategories(); 16 categoryOrAllGranted = cookieOptInCategories.Contains(category) || cookieOptInLevel == CookieOptInLevel.All; 17 } 18 19 return categoryOrAllGranted ? "granted" : "denied"; 20 } 21 22 bool AllowTracking() 23 { 24 bool allowTracking = true; 25 if (CookieManager.IsCookieManagementActive) 26 { 27 var cookieOptInLevel = CookieManager.GetCookieOptInLevel(); 28 var cookieOptInCategories = CookieManager.GetCookieOptInCategories(); 29 30 bool consentEither = (cookieOptInCategories.Contains("Statistical") || cookieOptInCategories.Contains("Marketing")); 31 bool consentFunctional = cookieOptInLevel == CookieOptInLevel.Functional; 32 bool consentAtLeastOne = cookieOptInLevel == CookieOptInLevel.All || (consentFunctional && consentEither); 33 34 allowTracking = consentAtLeastOne; 35 } 36 return allowTracking; 37 } 38 } 39 40 @{ 41 var cartSummaryPageId = Dynamicweb.Content.Services.Pages.GetPageByNavigationTag(Model.Area.ID, "CartSummary")?.ID; 42 bool enableMiniCart = Model.Area.Item?.GetBoolean("EnableOffcanvasMiniCart") ?? false; 43 var offcanvasMiniCartBehaviour = Model.Area.Item?.GetRawValueString("OffcanvasMinicartBehaviour", "3") ?? "3"; 44 bool miniCartEnabled = cartSummaryPageId != null && enableMiniCart; 45 var brandingPageId = Model.Area.Item?.GetInt32("BrandingPage") ?? 0; 46 var themePageId = Model.Area.Item?.GetInt32("ThemesPage") ?? 0; 47 var cssPageId = Model.Area.Item?.GetInt32("CssPage") ?? 0; 48 var brandingPage = brandingPageId != 0 ? Dynamicweb.Content.Services.Pages?.GetPage(brandingPageId) ?? null : null; 49 var themesParagraphs = themePageId != 0 ? Dynamicweb.Content.Services.Paragraphs?.GetParagraphsByPageId(themePageId) ?? null : null; 50 var cssParagraphs = cssPageId != 0 ? Dynamicweb.Content.Services.Paragraphs?.GetParagraphsByPageId(cssPageId) ?? null : null; 51 } 52 53 @if (themesParagraphs != null || brandingPage != null) 54 { 55 string swiftVersion = ReadFile("/Files/Templates/Designs/Swift/swift_version.txt"); 56 bool renderAsResponsive = Model.Area.Item.GetString("DeviceRendering", "responsive").Equals("responsive", StringComparison.OrdinalIgnoreCase); 57 bool renderMobile = Pageview.Device == Dynamicweb.Frontend.Devices.DeviceType.Mobile || Pageview.Device == Dynamicweb.Frontend.Devices.DeviceType.Tablet; 58 string responsiveClassDesktop = string.Empty; 59 string responsiveClassMobile = string.Empty; 60 if (renderAsResponsive) 61 { 62 responsiveClassDesktop = " d-none d-xl-block"; 63 responsiveClassMobile = " d-block d-xl-none"; 64 } 65 66 var headerDesktopLink = Model.Area.Item?.GetLink("HeaderDesktop") ?? null; 67 var headerMobileLink = Model.Area.Item?.GetLink("HeaderMobile") ?? null; 68 69 var footerDesktopLink = Model.Area.Item?.GetLink("FooterDesktop") ?? null; 70 var footerMobileLink = Model.Area.Item?.GetLink("FooterMobile") ?? null; 71 72 var disableWideBreakpoints = Model.Area?.Item?.GetRawValueString("DisableWideBreakpoints", "default"); 73 74 string customHeaderInclude = !string.IsNullOrEmpty(Model.Area.Item.GetRawValueString("CustomHeaderInclude")) ? Model.Area.Item.GetFile("CustomHeaderInclude").Name : string.Empty; 75 76 var themesParagraphLastChanged = Dynamicweb.Content.Services.Paragraphs.GetParagraphsByPageId(themePageId).OrderByDescending(p => p.Audit.LastModifiedAt).FirstOrDefault(); 77 var cssLastModified = brandingPage.Audit.LastModifiedAt > themesParagraphLastChanged.Audit.LastModifiedAt ? brandingPage.Audit.LastModifiedAt : themesParagraphLastChanged.Audit.LastModifiedAt; 78 79 var cssThemeAndBrandingStyleFileInfo = new System.IO.FileInfo(Dynamicweb.Core.SystemInformation.MapPath($"/Files/Templates/Designs/Swift/_parsed/Swift_css/Swift_styles_{Model.Area.ID}.min.css")); 80 81 82 if (cssPageId != 0) 83 { 84 var cssFileInfo = new System.IO.FileInfo(Dynamicweb.Core.SystemInformation.MapPath($"/Files/Templates/Designs/Swift/_parsed/Swift_css/Swift_css_styles_{Model.Area.ID}.css")); 85 var cssParagraphLastChanged = Dynamicweb.Content.Services.Paragraphs.GetParagraphsByPageId(cssPageId).OrderByDescending(p => p.Audit.LastModifiedAt).FirstOrDefault(); 86 if (!cssThemeAndBrandingStyleFileInfo.Exists || cssThemeAndBrandingStyleFileInfo.LastWriteTime < cssParagraphLastChanged.Audit.LastModifiedAt) 87 { 88 var cssPageview = Dynamicweb.Frontend.PageView.GetPageviewByPageID(cssPageId); 89 cssPageview.Redirect = false; 90 cssPageview.Output(); 91 } 92 } 93 94 if (!cssThemeAndBrandingStyleFileInfo.Exists || cssThemeAndBrandingStyleFileInfo.LastWriteTime < brandingPage.Audit.LastModifiedAt) 95 { 96 //Branding page has been saved or the file is missing. Rewrite the file to disc. 97 if (brandingPageId > 0) 98 { 99 var brandingPageview = Dynamicweb.Frontend.PageView.GetPageviewByPageID(brandingPageId); 100 brandingPageview.Redirect = false; 101 brandingPageview.Output(); 102 } 103 } 104 105 if (!cssThemeAndBrandingStyleFileInfo.Exists || cssThemeAndBrandingStyleFileInfo.LastWriteTime < themesParagraphLastChanged.Audit.LastModifiedAt) 106 { 107 //Branding page has been saved or the file is missing. Rewrite the file to disc. 108 if (themePageId > 0) 109 { 110 var themePageview = Dynamicweb.Frontend.PageView.GetPageviewByPageID(themePageId); 111 themePageview.Redirect = false; 112 themePageview.Output(); 113 } 114 } 115 116 // Schema.org details for PDP 117 bool isProductDetailsPage = Dynamicweb.Context.Current.Request.QueryString.AllKeys.Contains("ProductID"); 118 bool isArticlePage = Model.ItemType == "Swift_Article"; 119 string schemaOrgType = string.Empty; 120 121 if (isProductDetailsPage) 122 { 123 schemaOrgType = "itemscope=\"\" itemtype=\"https://schema.org/Product\""; 124 } 125 126 if (isArticlePage) 127 { 128 schemaOrgType = "itemscope=\"\" itemtype=\"https://schema.org/Article\""; 129 } 130 131 // Has ContactID? - used with ActiveCampaign 132 var ContactId = Dynamicweb.Context.Current.Request.QueryString["ContactId"]; 133 if (!string.IsNullOrWhiteSpace(ContactId)) 134 { 135 Dynamicweb.Environment.CookieManager.SetCookie("ContactId", ContactId, DateTime.Now.AddYears(1)); 136 } 137 138 var cssStyleFileInfo = new System.IO.FileInfo(Dynamicweb.Core.SystemInformation.MapPath("/Files/Templates/Designs/Swift/Assets/css/styles.css")); 139 var jsFileInfo = new System.IO.FileInfo(Dynamicweb.Core.SystemInformation.MapPath("/Files/Templates/Designs/Swift/Assets/js/scripts.js")); 140 var jsMainFileInfo = new System.IO.FileInfo(Dynamicweb.Core.SystemInformation.MapPath("/Files/Templates/Designs/Swift/Assets/js/main.js")); 141 142 string masterTheme = !string.IsNullOrWhiteSpace(Model.Area.Item.GetRawValueString("Theme")) ? " theme " + Model.Area.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 143 144 string favicon = Model.Area.Item.GetRawValueString("Favicon", "/Files/Templates/Designs/Swift/Assets/Images/favicon.png"); 145 string appleTouchIcon = Model.Area.Item.GetRawValueString("AppleTouchIcon", "/Files/Templates/Designs/Swift/Assets/Images/apple-touch-icon.png"); 146 147 string headerCssClass = "sticky-top"; 148 bool movePageBehind = false; 149 150 if (Model.PropertyItem != null) 151 { 152 headerCssClass = Model.PropertyItem.GetRawValueString("MoveThisPageBehindTheHeader", "sticky-top"); 153 movePageBehind = headerCssClass == "fixed-top" && !Pageview.IsVisualEditorMode ? true : false; 154 } 155 156 headerCssClass = headerCssClass == "" ? "sticky-top" : headerCssClass; 157 headerCssClass = Pageview.IsVisualEditorMode ? "" : headerCssClass; 158 159 string googleTagManagerID = Model.Area.Item.GetString("GoogleTagManagerID").Trim(); 160 string googleAnalyticsMeasurementID = Model.Area.Item.GetString("GoogleAnalyticsMeasurementID").Trim(); 161 162 bool allowTracking = AllowTracking(); 163 164 Dynamicweb.Context.Current.Response.AddHeader("link", $"</Files/Templates/Designs/Swift/Assets/css/styles.css?{cssStyleFileInfo.LastWriteTime.Ticks}>; rel=preload; as=style;"); 165 Dynamicweb.Context.Current.Response.AddHeader("link", $"</Files/Templates/Designs/Swift/_parsed/Swift_css/Swift_styles_{Model.Area.ID}.min.css?{cssLastModified.Ticks}>; rel=preload; as=style;"); 166 Dynamicweb.Context.Current.Response.AddHeader("link", $"</Files/Templates/Designs/Swift/Assets/js/scripts.js?{jsFileInfo.LastWriteTime.Ticks}>; rel=preload; as=script;"); 167 Dynamicweb.Context.Current.Response.AddHeader("link", $"</Files/Templates/Designs/Swift/Assets/js/main.js?{jsMainFileInfo.LastWriteTime.Ticks}>; rel=preload; as=script;"); 168 169 170 SetMetaTags(); 171 172 List<Dynamicweb.Content.Page> languages = new List<Dynamicweb.Content.Page>(); 173 174 var masterPage = Pageview.Area.IsMaster ? Pageview.Page : Pageview.Page.MasterPage; 175 languages.Add(masterPage); 176 if (masterPage?.Languages != null) 177 { 178 foreach (var language in masterPage.Languages) 179 { 180 languages.Add(language); 181 } 182 } 183 184 Uri url = Dynamicweb.Context.Current.Request.Url; 185 string hostName = url.Host; 186 187 <!doctype html> 188 <html lang="@Pageview.Area.CultureInfo.TwoLetterISOLanguageName"> 189 <head> 190 <!-- @swiftVersion --> 191 @* Required meta tags *@ 192 <meta charset="utf-8"> 193 <meta name="viewport" content="height=device-height, width=device-width, initial-scale=1.0"> 194 <link rel="shortcut icon" href="@favicon"> 195 <link rel="apple-touch-icon" href="@appleTouchIcon"> 196 197 @Model.MetaTags 198 199 @{ 200 var alreadyWrittenTwoletterIsos = new List<string>(); 201 @* Languages meta data *@ 202 foreach (var language in languages) 203 { 204 hostName = url.Host; 205 if (language?.Area != null) 206 { 207 if (language.Area?.MasterArea != null && !string.IsNullOrEmpty(language.Area.MasterArea.DomainLock)) 208 { 209 hostName = language.Area.MasterArea.DomainLock; //dk.domain.com or dk-domain.dk 210 } 211 if (language != null && language.Area != null && language.Published && language.Area.Active && language.Area.Published) 212 { 213 if (!string.IsNullOrEmpty(language.Area.DomainLock)) 214 { 215 hostName = language.Area.DomainLock; //dk.domain.com or dk-domain.dk 216 } 217 string querystring = $"Default.aspx?ID={language.ID}"; 218 if (!string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString["GroupID"])) 219 { 220 querystring += $"&GroupID={Dynamicweb.Context.Current.Request.QueryString["GroupID"]}"; 221 } 222 if (!string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString["ProductID"])) 223 { 224 querystring += $"&ProductID={Dynamicweb.Context.Current.Request.QueryString["ProductID"]}"; 225 } 226 if (!string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString["VariantID"])) 227 { 228 querystring += $"&VariantID={Dynamicweb.Context.Current.Request.QueryString["VariantID"]}"; 229 } 230 231 string friendlyUrl = Dynamicweb.Frontend.SearchEngineFriendlyURLs.GetFriendlyUrl(querystring); 232 if (language.Area.RedirectFirstPage && language.ParentPageId == 0 && language.Sort == 1) 233 { 234 friendlyUrl = "/"; 235 } 236 string href = $"{url.Scheme}://{hostName}{friendlyUrl}"; 237 238 239 <link rel="alternate" hreflang="@language.Area.CultureInfo.Name.ToLower()" href="@href"> 240 if (!alreadyWrittenTwoletterIsos.Contains(language.Area.CultureInfo.TwoLetterISOLanguageName)) 241 { 242 alreadyWrittenTwoletterIsos.Add(language.Area.CultureInfo.TwoLetterISOLanguageName); 243 <link rel="alternate" hreflang="@language.Area.CultureInfo.TwoLetterISOLanguageName.ToLower()" href="@href"> 244 } 245 } 246 } 247 } 248 } 249 250 <title>@Model.Title</title> 251 @* Bootstrap + Swift stylesheet *@ 252 <link href="/Files/Templates/Designs/Swift/Assets/css/styles.css?@cssStyleFileInfo.LastWriteTime.Ticks" rel="stylesheet" media="all" type="text/css"> 253 @* <style>pre.dw-error { display:none; }</style> *@ 254 @if (disableWideBreakpoints != "disableBoth") 255 { 256 <style> 257 @@media ( min-width: 1600px ) { 258 .container-xxl, 259 .container-xl, 260 .container-lg, 261 .container-md, 262 .container-sm, 263 .container { 264 max-width: 1520px; 265 } 266 } 267 </style> 268 269 270 271 if (disableWideBreakpoints != "disableUltraWideOnly") 272 { 273 <style> 274 @@media ( min-width: 1920px ) { 275 .container-xxl, 276 .container-xl, 277 .container-lg, 278 .container-md, 279 .container-sm, 280 .container { 281 max-width: 1820px; 282 } 283 } 284 </style> 285 } 286 } 287 288 @* Branding and Themes min stylesheet *@ 289 <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"> 290 <script src="/Files/Templates/Designs/Swift/Assets/js/scripts.js?@jsFileInfo.LastWriteTime.Ticks"></script> 291 <script src="/Files/Templates/Designs/Swift/Assets/js/main.js?@jsMainFileInfo.LastWriteTime.Ticks"></script> 292 <script type="module"> 293 swift.Scroll.hideHeadersOnScroll(); 294 swift.Scroll.handleAlternativeTheme(); 295 296 //Only load if AOS 297 const aosColumns = document.querySelectorAll('[data-aos]'); 298 if (aosColumns.length > 0) { 299 swift.AssetLoader.Load('/Files/Templates/Designs/Swift/Assets/js/aos.js?@jsFileInfo.LastWriteTime.Ticks', 'js'); 300 document.addEventListener('load.swift.assetloader', function () { 301 AOS.init({ duration: 400, delay: 100, easing: 'ease-in-out', mirror: false, disable: window.matchMedia('(prefers-reduced-motion: reduce)') }); 302 }); 303 } 304 </script> 305 306 @* Google gtag method - always include even if it is not used for anything *@ 307 <script> 308 window.dataLayer = window.dataLayer || []; 309 function gtag() { 310 //dataLayer.push(arguments); 311 if(arguments[2] && arguments[2]?.items) { 312 dataLayer.push({ ecommerce: null }); 313 dataLayer.push({ 314 event: arguments[1], 315 ecommerce: arguments[2] 316 }); 317 } else { 318 dataLayer.push(arguments); 319 } 320 } 321 </script> 322 @* Google tag manager *@ 323 @if (!string.IsNullOrWhiteSpace(googleTagManagerID)) 324 { 325 <script> 326 gtag('consent', 'default', { 327 'ad_storage': 'denied', 328 'ad_user_data': 'denied', 329 'ad_personalization': 'denied', 330 'analytics_storage': 'denied' 331 }); 332 </script> 333 <script> 334 (function (w, d, s, l, i) { 335 w[l] = w[l] || []; w[l].push({ 336 'gtm.start': 337 new Date().getTime(), event: 'gtm.js' 338 }); var f = d.getElementsByTagName(s)[0], 339 j = d.createElement(s), dl = l != 'dataLayer' ? '&l=' + l : ''; j.async = true; j.src = 340 'https://www.googletagmanager.com/gtm.js?id=' + i + dl; f.parentNode.insertBefore(j, f); 341 })(window, document, 'script', 'dataLayer', '@(googleTagManagerID)'); 342 </script> 343 if (allowTracking) 344 { 345 string adConsent = GetCookieOptInPermission("Marketing"); 346 string analyticsConsent = GetCookieOptInPermission("Statistical"); 347 <script> 348 gtag('consent', 'update', { 349 'ad_storage': '@adConsent', 350 'ad_user_data': '@adConsent', 351 'ad_personalization': '@adConsent', 352 'analytics_storage': '@analyticsConsent' 353 }); 354 </script> 355 } 356 } 357 358 @if (!string.IsNullOrWhiteSpace(googleAnalyticsMeasurementID) && allowTracking) 359 { 360 var GoogleAnalyticsDebugMode = ""; 361 362 if (Model.Area.Item.GetBoolean("EnableGoogleAnalyticsDebugMode")) 363 { 364 GoogleAnalyticsDebugMode = ", {'debug_mode': true}"; 365 } 366 367 <script async src="https://www.googletagmanager.com/gtag/js?id=@googleAnalyticsMeasurementID"></script> 368 <script> 369 gtag('js', new Date()); 370 gtag('config', '@googleAnalyticsMeasurementID'@GoogleAnalyticsDebugMode); 371 </script> 372 } 373 374 @if (!string.IsNullOrWhiteSpace(customHeaderInclude)) 375 { 376 @RenderPartial($"Components/Custom/{customHeaderInclude}") 377 } 378 </head> 379 <body class="brand @(masterTheme)" id="page@(Model.ID)"> 380 381 @* Google tag manager *@ 382 @if (!string.IsNullOrWhiteSpace(googleTagManagerID) && allowTracking) 383 { 384 <noscript> 385 <iframe src="https://www.googletagmanager.com/ns.html?id=@(googleTagManagerID)" 386 height="0" width="0" style="display:none;visibility:hidden"></iframe> 387 </noscript> 388 } 389 390 @if (renderAsResponsive || !renderMobile) 391 { 392 var IsCatalogPage = Pageview.Page.ItemType == "Swift_CatalogPage"; 393 394 <header class="page-header @headerCssClass top-0@(responsiveClassDesktop)" id="page-header-desktop"> 395 @if (IsCatalogPage) 396 { 397 // Current page path. Page Id and title 398 var PagePath = Pageview.Page.GetPath() 399 .Select(a => new KeyValuePair<int, string>(a.ID, a.MenuText)) 400 .ToDictionary(x => x.Key, x => x.Value); 401 402 var CatalogHeader = Dynamicweb.Content.Services.Pages.GetPageByNavigationTag(Pageview.Area.ID, "CatalogHeader"); 403 var RootpathBrandname = PagePath.Skip(3).FirstOrDefault().Value; 404 var BrandName = RootpathBrandname?.ToLower() switch 405 { 406 "outwell" => "Swift_styles_3", 407 "robens" => "Swift_styles_4", 408 "easy camp" => "Swift_styles_2", 409 _ => "" 410 }; 411 <link href="/Files/Templates/Designs/Swift/_parsed/Swift_css/@(BrandName).min.css?@cssLastModified.Ticks" rel="stylesheet" media="all" type="text/css" data-last-modified-content="@cssLastModified"> 412 @RenderGrid(CatalogHeader.ID) 413 } else 414 { 415 if (headerDesktopLink != null) 416 { 417 @RenderGrid(headerDesktopLink.PageId) 418 } 419 } 420 </header> 421 } 422 423 @if ((renderAsResponsive || renderMobile)) 424 { 425 <header class="page-header @headerCssClass top-0@(responsiveClassMobile)" id="page-header-mobile"> 426 @if (headerMobileLink != null) 427 { 428 @RenderGrid(headerMobileLink.PageId) 429 } 430 </header> 431 } 432 433 <div data-intersect></div> 434 435 <main id="content" @(schemaOrgType)> 436 @inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.PageViewModel> 437 @using System 438 @using Dynamicweb.Ecommerce.ProductCatalog 439 440 441 @{ 442 string productIdFromUrl = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString.Get("ProductID")) ? Dynamicweb.Context.Current.Request.QueryString.Get("ProductID") : string.Empty; 443 bool isProductDetail = !string.IsNullOrEmpty(productIdFromUrl) && Pageview.Page.NavigationTag.ToLower() == "shop"; 444 445 bool isArticlePagePage = Model.ItemType == "Swift_Article"; 446 bool isArticleListPage = Model.ItemType == "Swift_ArticleListPage"; 447 string schemaOrgProp = string.Empty; 448 if(isArticlePagePage) 449 { 450 schemaOrgProp = "itemprop=\"articleBody\""; 451 } 452 453 string theme = ""; 454 string gridContent = ""; 455 456 if (Model.PropertyItem != null) 457 { 458 theme = !string.IsNullOrWhiteSpace(Model.PropertyItem.GetRawValueString("Theme")) ? "theme " + Model.PropertyItem.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 459 } 460 461 if (Model.Item != null || Pageview.IsVisualEditorMode) 462 { 463 if (!isProductDetail) 464 { 465 gridContent = Model.Grid("Grid", "Grid", "default:true;sort:1", "Page"); 466 } 467 else 468 { 469 var productObject = Dynamicweb.Ecommerce.Services.Products.GetProductById(productIdFromUrl, "", Pageview.Area.EcomLanguageId); 470 var detailPage = Dynamicweb.Ecommerce.Services.ProductGroups.GetGroup(productObject.PrimaryGroupId)?.Meta.PrimaryPage ?? string.Empty; 471 var detailPageId = detailPage != string.Empty ? Convert.ToInt16(detailPage.Substring(detailPage.LastIndexOf('=') + 1)) : GetPageIdByNavigationTag("ProductDetailPage"); 472 473 @RenderGrid(detailPageId) 474 } 475 } 476 477 bool doNotRenderPage = false; 478 479 //Check if we are on the poduct detail page, and if there is data to render 480 ProductViewModel product = new ProductViewModel(); 481 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 482 { 483 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 484 if (string.IsNullOrEmpty(product.Id)) { 485 doNotRenderPage = true; 486 } 487 } 488 if(!string.IsNullOrWhiteSpace(productIdFromUrl)) 489 { 490 <script> 491 gtag("event", "view_item", { 492 currency: "@product.Price.CurrencyCode", 493 value: @PriceViewModelExtensions.ToStringInvariant(product.Price), 494 items: [ 495 { 496 item_id: "@product.Number", 497 item_name: "@Dynamicweb.Core.Encoders.HtmlEncoder.JavaScriptStringEncode(product.Name)", 498 currency: "@product.Price.CurrencyCode", 499 price: @PriceViewModelExtensions.ToStringInvariant(product.Price) 500 } 501 ] 502 }); 503 </script> 504 } 505 506 //Render the page 507 if (!doNotRenderPage) { 508 string itemIdentifier = Model?.Item?.SystemName != null ? "item_" + Model.Item.SystemName.ToLower() : "item_Swift_Page"; 509 510 if (Pageview.IsVisualEditorMode) { 511 @Model.Placeholder("dwcontent", "content", "default:true;sort:1") 512 } 513 514 <div class="@theme @itemIdentifier" @schemaOrgProp> 515 @if (isArticleListPage) 516 { 517 var hx = $"hx-get=\"{Dynamicweb.Frontend.SearchEngineFriendlyURLs.GetFriendlyUrl(Model.ID)}\" hx-select=\"#content\" hx-target=\"#content\" hx-swap=\"outerHTML\" hx-trigger=\"change\" hx-headers='{{\"feed\": \"true\"}}' hx-push-url=\"true\" hx-indicator=\"#ArticleFacetForm\""; 518 519 <form @hx id="ArticleFacetForm"> 520 @gridContent 521 </form> 522 <script type="module" src="/Files/Templates/Designs/Swift/Assets/js/htmx.js"></script> 523 <script type="module"> 524 document.addEventListener('htmx:confirm', (event) => { 525 let filters = event.detail.elt.querySelectorAll('select'); 526 for (var i = 0; i < filters.length; i++) { 527 let input = filters[i]; 528 if (input.name && !input.value) { 529 input.name = ''; 530 } 531 } 532 }); 533 534 document.addEventListener('htmx:beforeOnLoad', (event) => { 535 swift.Scroll.stopIntersectionObserver(); 536 }); 537 538 document.addEventListener('htmx:afterOnLoad', () => { 539 swift.Scroll.hideHeadersOnScroll(); 540 swift.Scroll.handleAlternativeTheme(); 541 }); 542 </script> 543 } 544 else 545 { 546 @gridContent 547 } 548 </div> 549 550 } else { 551 <div class="container"> 552 <div class="alert alert-info" role="alert">@Translate("Sorry. There is nothing to view here")</div> 553 </div> 554 } 555 556 if (!Model.IsCurrentUserAllowed) 557 { 558 int signInPage = GetPageIdByNavigationTag("SignInPage"); 559 int dashboardPage = GetPageIdByNavigationTag("MyAccountDashboardPage"); 560 561 if (!Pageview.IsVisualEditorMode) 562 { 563 if (signInPage != 0) 564 { 565 if (signInPage != Model.ID) { 566 Dynamicweb.Context.Current.Response.Redirect("/Default.aspx?ID=" + signInPage); 567 } else { 568 if (dashboardPage != 0) { 569 Dynamicweb.Context.Current.Response.Redirect("/Default.aspx?ID=" + dashboardPage); 570 } else { 571 Dynamicweb.Context.Current.Response.Redirect("/"); 572 } 573 } 574 } 575 else 576 { 577 <div class="alert alert-dark m-0" role="alert"> 578 <span>@Translate("You do not have access to this page")</span> 579 </div> 580 } 581 } 582 else 583 { 584 <div class="alert alert-dark m-0" role="alert"> 585 <span>@Translate("To work on this page, you must be signed in, in the frontend")</span> 586 </div> 587 } 588 } 589 } 590 591 </main> 592 593 <link rel="stylesheet" href="/Files/Templates/Designs/Swift/Assets/css/glightbox.min.css" /> 594 <script src="/Files/Templates/Designs/Swift/Assets/js/glightbox.min.js"></script> 595 <script> 596 var lightbox = GLightbox({ 597 touchNavigation: true, 598 loop: false, 599 autoplayVideos: true, 600 videosWidth: '80vw', 601 dragAutoSnap: true, 602 plyr: { 603 config: { 604 quality: 720, 605 muted: false, 606 volume: 100, 607 youtube: { noCookie: true, rel: 0, showinfo: 0, iv_load_policy: 3, modestbranding: 1 } 608 } 609 } 610 }); 611 </script> 612 <script> 613 document.addEventListener('DOMContentLoaded', () => { 614 document.querySelectorAll('a').forEach(link => { 615 const href = link.getAttribute('href'); 616 if (href && href.startsWith('https')) { 617 link.setAttribute('target', '_blank'); 618 } else { 619 link.setAttribute('target', '_self'); 620 } 621 }); 622 }); 623 </script> 624 625 @if (renderAsResponsive || !renderMobile) 626 { 627 <footer class="page-footer@(responsiveClassDesktop)" id="page-footer-desktop"> 628 @if (footerDesktopLink != null) 629 { 630 @RenderGrid(footerDesktopLink.PageId) 631 } 632 </footer> 633 } 634 635 @if (renderAsResponsive || renderMobile) 636 { 637 <footer class="page-footer@(responsiveClassMobile)" id="page-footer-mobile"> 638 @if (footerMobileLink != null) 639 { 640 @RenderGrid(footerMobileLink.PageId) 641 } 642 </footer> 643 } 644 645 @* Render any offcanvas menu here *@ 646 @RenderSnippet("offcanvas") 647 648 @{ 649 bool isErpConnectionDown = !Dynamicweb.Core.Converter.ToBoolean(Context.Current.Items["IsWebServiceConnectionAvailable"]); 650 string iconPath = "/Files/Templates/Designs/Swift/Assets/icons/"; 651 } 652 653 @* Language selector modal *@ 654 <div class="modal fade" id="PreferencesModal" tabindex="-1" aria-hidden="true"> 655 <div class="modal-dialog modal-dialog-centered modal-sm" id="PreferencesModalContent"> 656 @* The content here comes from an external request *@ 657 </div> 658 </div> 659 660 @* Toast *@ 661 <div aria-live="polite" aria-atomic="true"> 662 <div class="toast-container position-fixed end-0 p-3" style="top:50px;z-index:1500;"> 663 <div id="notificationToast" class="toast rounded-6 overflow-hidden" role="alert" aria-live="assertive" aria-atomic="true" data-bs-delay="1000"> 664 <div class="toast-body d-flex align-items-end gap-3 theme theme-gray bg-dark text-light"> 665 @ReadFile(iconPath + "check.svg") 666 <div id="notificationToast_Text" class=""></div> 667 </div> 668 </div> 669 </div> 670 </div> 671 672 @* Modal for dynamic content *@ 673 <div class="modal fade js-product" id="DynamicModal" tabindex="-1" aria-hidden="true"> 674 <div class="modal-dialog modal-dialog-centered modal-md"> 675 <div class="modal-content theme light" id="DynamicModalContent"> 676 @* The content here comes from an external request *@ 677 </div> 678 </div> 679 </div> 680 681 @* Offcanvas for dynamic content *@ 682 <div class="offcanvas offcanvas-end theme light" tabindex="-1" id="DynamicOffcanvas"> 683 @* The content here comes from an external request *@ 684 </div> 685 686 @if (Model.Area.Item.GetBoolean("ShowErpDownMessage") && !Dynamicweb.Core.Converter.ToBoolean(Context.Current.Items["IsWebServiceConnectionAvailable"])) 687 { 688 string erpDownMessageTheme = !string.IsNullOrWhiteSpace(Model.Area.Item.GetRawValueString("ErpDownMessageTheme")) ? " theme " + Model.Area.Item.GetRawValueString("ErpDownMessageTheme").Replace(" ", "").Trim().ToLower() : "theme light"; 689 690 <div class="position-fixed bottom-0 end-0 p-3" style="z-index: 1040"> 691 <div class="toast fade show border-0 @erpDownMessageTheme" role="alert" aria-live="assertive" aria-atomic="true"> 692 <div class="toast-header"> 693 <strong class="me-auto">@Translate("Connection down")</strong> 694 <button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button> 695 </div> 696 <div class="toast-body"> 697 @Translate("We are experiencing some connectivity issues. Not all features may be available to you.") 698 </div> 699 </div> 700 </div> 701 } 702 703 @if (miniCartEnabled) 704 { 705 @* Open MiniCart when the cart is updated *@ 706 <script type="module"> 707 document.addEventListener('updated.swift.cart', (event) => { 708 let orderContext = event?.detail?.formData?.get("OrderContext"); 709 updateCartSummary(orderContext); 710 711 @if (offcanvasMiniCartBehaviour == "2" || offcanvasMiniCartBehaviour == "3") { 712 <text>openMiniCartOffcanvas();</text> 713 } 714 }); 715 </script> 716 717 if (offcanvasMiniCartBehaviour == "1" || offcanvasMiniCartBehaviour == "3") 718 { 719 @* Open MiniCart when toggle is clicked *@ 720 <script type="module"> 721 let miniCartToggles = document.querySelectorAll('.mini-cart-quantity'); 722 miniCartToggles?.forEach((toggle) => { 723 toggle.parentElement.addEventListener('click', (event) => { 724 event.preventDefault(); 725 let orderContext = toggle.dataset?.orderContext; 726 updateCartSummary(orderContext); 727 728 openMiniCartOffcanvas(); 729 }); 730 }); 731 </script> 732 } 733 734 <script> 735 736 const updateCartSummary = (orderContext) => { 737 const dynamicOffcanvas = document.getElementById('DynamicOffcanvas'); 738 swift.PageUpdater.UpdateFromUrlInline(event, '/Default.aspx?ID=@(cartSummaryPageId)&CartType=minicart&RequestPageID=@(Pageview.Page.ID)&OrderContext=' + orderContext +'', 'Swift_CartSummary.cshtml', dynamicOffcanvas); 739 }; 740 741 const openMiniCartOffcanvas = () => { 742 const dynamicOffcanvas = document.getElementById('DynamicOffcanvas'); 743 const miniCartOffcanvas = bootstrap.Offcanvas.getOrCreateInstance(dynamicOffcanvas); 744 dynamicOffcanvas.classList.add('overflow-y-auto'); 745 746 if (!miniCartOffcanvas._isShown) { 747 miniCartOffcanvas.show(); 748 hideActiveOffcanvases(miniCartOffcanvas); 749 } 750 }; 751 752 const hideActiveOffcanvases = (miniCartOffcanvas) => { 753 let activeOffcanvases = document.querySelectorAll('.offcanvas.show'); 754 activeOffcanvases?.forEach((offCanvas) => { 755 offCanvas = bootstrap.Offcanvas.getInstance(offCanvas); 756 if (offCanvas !== miniCartOffcanvas) { 757 offCanvas.hide(); 758 } 759 }); 760 }; 761 762 </script> 763 } 764 765 @RenderPartial("Components/Custom/CustomLanguageModal.cshtml") 766 </body> 767 768 </html> 769 770 } 771 else if (Pageview.IsVisualEditorMode) 772 { 773 <head> 774 <title>@Model.Title</title> 775 @* Bootstrap + Swift stylesheet *@ 776 <link href="/Files/Templates/Designs/Swift/Assets/css/styles.css" rel="stylesheet" media="all" type="text/css"> 777 </head> 778 <body class="p-3"> 779 <div class="alert alert-danger" role="alert"> 780 @Translate("Basic Swift setup is needed!") 781 </div> 782 783 @if (brandingPage == null) 784 { 785 <div class="alert alert-warning" role="alert"> 786 @Translate("Please add a Branding page and reference it in website settings") 787 </div> 788 } 789 790 @if (themesParagraphs == null) 791 { 792 <div class="alert alert-warning" role="alert"> 793 @Translate("Please add a Themes collection page and reference it in website settings") 794 </div> 795 } 796 </body> 797 } 798 799 800 @functions { 801 void SetMetaTags() 802 { 803 //Verification Tokens 804 string siteVerificationGoogle = Model.Area.Item.GetString("Google_Site_Verification") != null ? Model.Area.Item.GetString("Google_Site_Verification") : ""; 805 806 //Generic Site Values 807 string openGraphFacebookAppID = Model.Area.Item.GetString("Fb_app_id") != null ? Model.Area.Item.GetString("Fb_app_id") : ""; 808 string openGraphType = Model.Area.Item.GetString("Open_Graph_Type") != null ? Model.Area.Item.GetString("Open_Graph_Type") : ""; 809 string openGraphSiteName = Model.Area.Item.GetString("Open_Graph_Site_Name") != null ? Model.Area.Item.GetString("Open_Graph_Site_Name") : ""; 810 811 string twitterCardSite = Model.Area.Item.GetString("Twitter_Site") != null ? Model.Area.Item.GetString("Twitter_Site") : ""; 812 813 //Page specific values 814 string openGraphSiteTitle = Model.Area.Item.GetString("Open_Graph_Title") != null ? Model.Area.Item.GetString("Open_Graph_Title") : ""; 815 FileViewModel openGraphImage = Model.Area.Item.GetFile("Open_Graph_Image"); 816 string openGraphImageALT = Model.Area.Item.GetString("Open_Graph_Image_ALT") != null ? Model.Area.Item.GetString("Open_Graph_Image_ALT") : ""; 817 string openGraphDescription = Model.Area.Item.GetString("Open_Graph_Description") != null ? Model.Area.Item.GetString("Open_Graph_Description") : ""; 818 819 string twitterCardURL = Model.Area.Item.GetString("Twitter_URL") != null ? Model.Area.Item.GetString("Twitter_URL") : ""; 820 string twitterCardTitle = Model.Area.Item.GetString("Twitter_Title") != null ? Model.Area.Item.GetString("Twitter_Title") : ""; 821 string twitterCardDescription = Model.Area.Item.GetString("Twitter_Description") != null ? Model.Area.Item.GetString("Twitter_Description") : ""; 822 FileViewModel twitterCardImage = Model.Area.Item.GetFile("Twitter_Image"); 823 string twitterCardImageALT = Model.Area.Item.GetString("Twitter_Image_ALT") != null ? Model.Area.Item.GetString("Twitter_Image_ALT") : ""; 824 string topImage = Pageview.Page.TopImage.StartsWith("/Files", StringComparison.OrdinalIgnoreCase) ? Pageview.Page.TopImage : $"/Files{Pageview.Page.TopImage}"; 825 826 if (string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString["ProductID"])) 827 { 828 if (!string.IsNullOrEmpty(Model.Description)) 829 { 830 Pageview.Meta.AddTag($"<meta property=\"og:description\" content=\"{Model.Description}\">"); 831 } 832 else 833 { 834 Pageview.Meta.AddTag($"<meta property=\"og:description\" content=\"{openGraphDescription}\">"); 835 } 836 837 if (!string.IsNullOrEmpty(Pageview.Page.TopImage)) 838 { 839 Pageview.Meta.AddTag($"<meta property=\"og:image\" content=\"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}{topImage}\">"); 840 Pageview.Meta.AddTag($"<meta property=\"og:image:secure_url\" content=\"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}{topImage}\">"); 841 } 842 else if (openGraphImage != null) 843 { 844 Pageview.Meta.AddTag($"<meta property=\"og:image\" content=\"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}{openGraphImage.Path}\">"); 845 Pageview.Meta.AddTag($"<meta property=\"og:image:secure_url\" content=\"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}{openGraphImage.Path}\">"); 846 } 847 848 if (!string.IsNullOrEmpty(openGraphImageALT)) 849 { 850 Pageview.Meta.AddTag($"<meta property=\"og:image:alt\" content=\"{openGraphImageALT}\">"); 851 } 852 if (!string.IsNullOrEmpty(twitterCardDescription)) 853 { 854 Pageview.Meta.AddTag("twitter:description", twitterCardDescription); 855 } 856 857 if (!string.IsNullOrEmpty(Pageview.Page.TopImage)) 858 { 859 Pageview.Meta.AddTag("twitter:image", $"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}{topImage}"); 860 } 861 else if (twitterCardImage != null) 862 { 863 Pageview.Meta.AddTag("twitter:image", $"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}{openGraphImage.Path}"); 864 } 865 866 if (!string.IsNullOrEmpty(twitterCardImageALT)) 867 { 868 Pageview.Meta.AddTag("twitter:image:alt", twitterCardImageALT); 869 } 870 } 871 872 if (!string.IsNullOrEmpty(siteVerificationGoogle)) 873 { 874 Pageview.Meta.AddTag("google-site-verification", siteVerificationGoogle); 875 } 876 877 if (!string.IsNullOrEmpty(openGraphFacebookAppID)) 878 { 879 Pageview.Meta.AddTag($"<meta property=\"fb:app_id\" content=\"{openGraphFacebookAppID}\">"); 880 } 881 882 if (!string.IsNullOrEmpty(openGraphType)) 883 { 884 Pageview.Meta.AddTag($"<meta property=\"og:type\" content=\"{openGraphType}\">"); 885 } 886 887 if (!string.IsNullOrEmpty(openGraphSiteName)) 888 { 889 Pageview.Meta.AddTag($"<meta property=\"og:url\" content=\"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}{Pageview.SearchFriendlyUrl}\">"); 890 } 891 892 if (!string.IsNullOrEmpty(openGraphSiteName)) 893 { 894 Pageview.Meta.AddTag($"<meta property=\"og:site_name\" content=\"{openGraphSiteName}\">"); 895 } 896 897 if (!string.IsNullOrEmpty(Model.Title)) 898 { 899 Pageview.Meta.AddTag($"<meta property=\"og:title\" content=\"{Model.Title}\">"); 900 } 901 else 902 { 903 Pageview.Meta.AddTag($"<meta property=\"og:title\" content=\"{openGraphSiteTitle}\">"); 904 } 905 906 if (!string.IsNullOrEmpty(twitterCardSite)) 907 { 908 Pageview.Meta.AddTag("twitter:site", twitterCardSite); 909 } 910 911 if (!string.IsNullOrEmpty(twitterCardURL)) 912 { 913 Pageview.Meta.AddTag("twitter:url", twitterCardURL); 914 } 915 916 if (!string.IsNullOrEmpty(twitterCardTitle)) 917 { 918 Pageview.Meta.AddTag("twitter:title", twitterCardTitle); 919 } 920 } 921 } 922