Error executing template "Designs/Swift/Swift_Page.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at CompiledRazorTemplates.Dynamic.RazorEngine_7e49eaa65a00433f8cda9b7ebefb7438.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 if (!alreadyWrittenTwoletterIsos.Contains(language.Area.CultureInfo.Name.ToLower())) 238 { 239 alreadyWrittenTwoletterIsos.Add(language.Area.CultureInfo.Name.ToLower()); 240 <link rel="alternate" hreflang="@language.Area.CultureInfo.Name.ToLower()" href="@href.TrimEnd('/')"> 241 } 242 } 243 } 244 } 245 } 246 247 <title>@Model.Title</title> 248 @* Bootstrap + Swift stylesheet *@ 249 <link href="/Files/Templates/Designs/Swift/Assets/css/styles.css?@cssStyleFileInfo.LastWriteTime.Ticks" rel="stylesheet" media="all" type="text/css"> 250 @* <style>pre.dw-error { display:none; }</style> *@ 251 @if (disableWideBreakpoints != "disableBoth") 252 { 253 <style> 254 @@media ( min-width: 1600px ) { 255 .container-xxl, 256 .container-xl, 257 .container-lg, 258 .container-md, 259 .container-sm, 260 .container { 261 max-width: 1520px; 262 } 263 } 264 </style> 265 266 267 268 if (disableWideBreakpoints != "disableUltraWideOnly") 269 { 270 <style> 271 @@media ( min-width: 1920px ) { 272 .container-xxl, 273 .container-xl, 274 .container-lg, 275 .container-md, 276 .container-sm, 277 .container { 278 max-width: 1820px; 279 } 280 } 281 </style> 282 } 283 } 284 285 @* Branding and Themes min stylesheet *@ 286 <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"> 287 <script src="/Files/Templates/Designs/Swift/Assets/js/scripts.js?@jsFileInfo.LastWriteTime.Ticks"></script> 288 <script src="/Files/Templates/Designs/Swift/Assets/js/main.js?@jsMainFileInfo.LastWriteTime.Ticks"></script> 289 <script type="module"> 290 swift.Scroll.hideHeadersOnScroll(); 291 swift.Scroll.handleAlternativeTheme(); 292 293 //Only load if AOS 294 const aosColumns = document.querySelectorAll('[data-aos]'); 295 if (aosColumns.length > 0) { 296 swift.AssetLoader.Load('/Files/Templates/Designs/Swift/Assets/js/aos.js?@jsFileInfo.LastWriteTime.Ticks', 'js'); 297 document.addEventListener('load.swift.assetloader', function () { 298 AOS.init({ duration: 400, delay: 100, easing: 'ease-in-out', mirror: false, disable: window.matchMedia('(prefers-reduced-motion: reduce)') }); 299 }); 300 } 301 </script> 302 303 @* Google gtag method - always include even if it is not used for anything *@ 304 <script> 305 window.dataLayer = window.dataLayer || []; 306 function gtag() { 307 //dataLayer.push(arguments); 308 if(arguments[2] && arguments[2]?.items) { 309 // try update items 310 // arguments[2]?.items?.forEach(itm => { 311 // const itm_brand = document.querySelector('[data-gtagbrand="'+itm.item_id+'"]')?.innerText; 312 // if(itm_brand) { 313 // itm['item_brand'] = itm_brand; 314 // } 315 // }); 316 317 dataLayer.push({ ecommerce: null }); 318 dataLayer.push({ 319 event: arguments[1], 320 ecommerce: arguments[2] 321 }); 322 } else { 323 dataLayer.push(arguments); 324 } 325 } 326 </script> 327 328 @if (!string.IsNullOrWhiteSpace(customHeaderInclude)) 329 { 330 @RenderPartial($"Components/Custom/{customHeaderInclude}") 331 } 332 <style> 333 .item_swift_productlistitemrepeater { 334 font-size: 0.85rem; 335 } 336 </style> 337 </head> 338 <body class="brand @(masterTheme)" id="page@(Model.ID)"> 339 340 @* Google tag manager *@ 341 @if (!string.IsNullOrWhiteSpace(googleTagManagerID) && allowTracking) 342 { 343 <noscript> 344 <iframe src="@googleTagManagerID" height="0" width="0" style="display:none;visibility:hidden"></iframe> 345 </noscript> 346 } 347 348 @if (renderAsResponsive || !renderMobile) 349 { 350 var IsCatalogPage = Pageview.Page.ItemType == "Swift_CatalogPage"; 351 352 <header class="page-header @headerCssClass top-0@(responsiveClassDesktop)" id="page-header-desktop"> 353 @if (IsCatalogPage) 354 { 355 // Current page path. Page Id and title 356 var PagePath = Pageview.Page.GetPath() 357 .Select(a => new KeyValuePair<int, string>(a.ID, a.MenuText)) 358 .ToDictionary(x => x.Key, x => x.Value); 359 360 var CatalogHeader = Dynamicweb.Content.Services.Pages.GetPageByNavigationTag(Pageview.Area.ID, "CatalogHeader"); 361 var RootpathBrandname = PagePath.Skip(3).FirstOrDefault().Value; 362 var BrandName = RootpathBrandname?.ToLower() switch 363 { 364 "outwell" => "Swift_styles_3", 365 "robens" => "Swift_styles_4", 366 "easy camp" => "Swift_styles_2", 367 _ => "" 368 }; 369 <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"> 370 @RenderGrid(CatalogHeader.ID) 371 } else 372 { 373 if (headerDesktopLink != null) 374 { 375 @RenderGrid(headerDesktopLink.PageId) 376 } 377 } 378 </header> 379 } 380 381 @if ((renderAsResponsive || renderMobile)) 382 { 383 <header class="page-header @headerCssClass top-0@(responsiveClassMobile)" id="page-header-mobile"> 384 @if (headerMobileLink != null) 385 { 386 @RenderGrid(headerMobileLink.PageId) 387 } 388 </header> 389 } 390 391 <div data-intersect></div> 392 393 <main id="content" style="user-select:none;" @(schemaOrgType)> 394 @inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.PageViewModel> 395 @using System 396 @using Dynamicweb.Ecommerce.ProductCatalog 397 398 399 @{ 400 string productIdFromUrl = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString.Get("ProductID")) ? Dynamicweb.Context.Current.Request.QueryString.Get("ProductID") : string.Empty; 401 bool isProductDetail = !string.IsNullOrEmpty(productIdFromUrl) && Pageview.Page.NavigationTag.ToLower() == "shop"; 402 403 bool isArticlePagePage = Model.ItemType == "Swift_Article"; 404 bool isArticleListPage = Model.ItemType == "Swift_ArticleListPage"; 405 string schemaOrgProp = string.Empty; 406 if(isArticlePagePage) 407 { 408 schemaOrgProp = "itemprop=\"articleBody\""; 409 } 410 411 string theme = ""; 412 string gridContent = ""; 413 414 if (Model.PropertyItem != null) 415 { 416 theme = !string.IsNullOrWhiteSpace(Model.PropertyItem.GetRawValueString("Theme")) ? "theme " + Model.PropertyItem.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 417 } 418 419 if (Model.Item != null || Pageview.IsVisualEditorMode) 420 { 421 if (!isProductDetail) 422 { 423 gridContent = Model.Grid("Grid", "Grid", "default:true;sort:1", "Page"); 424 } 425 else 426 { 427 var productObject = Dynamicweb.Ecommerce.Services.Products.GetProductById(productIdFromUrl, "", Pageview.Area.EcomLanguageId); 428 var detailPage = Dynamicweb.Ecommerce.Services.ProductGroups.GetGroup(productObject.PrimaryGroupId)?.Meta.PrimaryPage ?? string.Empty; 429 var detailPageId = detailPage != string.Empty ? Convert.ToInt16(detailPage.Substring(detailPage.LastIndexOf('=') + 1)) : GetPageIdByNavigationTag("ProductDetailPage"); 430 431 @RenderGrid(detailPageId) 432 } 433 } 434 435 bool doNotRenderPage = false; 436 437 //Check if we are on the poduct detail page, and if there is data to render 438 ProductViewModel product = new ProductViewModel(); 439 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 440 { 441 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 442 if (string.IsNullOrEmpty(product.Id)) { 443 doNotRenderPage = true; 444 } 445 } 446 if(!string.IsNullOrWhiteSpace(productIdFromUrl)) 447 { 448 <script> 449 450 gtag("event", "view_item", { 451 currency: "@product.Price.CurrencyCode", 452 value: @PriceViewModelExtensions.ToStringInvariant(product.Price), 453 items: [ 454 { 455 item_id: "@product.Id", 456 item_name: "@Dynamicweb.Core.Encoders.HtmlEncoder.JavaScriptStringEncode(product.Name)", 457 item_brand: "@product.ProductFields.GetValueOrDefault("Collection")?.Value", 458 currency: "@product.Price.CurrencyCode", 459 price: @PriceViewModelExtensions.ToStringInvariant(product.Price) 460 } 461 ] 462 }); 463 </script> 464 } 465 466 //Render the page 467 if (!doNotRenderPage) { 468 string itemIdentifier = Model?.Item?.SystemName != null ? "item_" + Model.Item.SystemName.ToLower() : "item_Swift_Page"; 469 470 if (Pageview.IsVisualEditorMode) { 471 @Model.Placeholder("dwcontent", "content", "default:true;sort:1") 472 } 473 474 <div class="@theme @itemIdentifier" @schemaOrgProp> 475 @if (isArticleListPage) 476 { 477 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\""; 478 479 <form @hx id="ArticleFacetForm"> 480 @gridContent 481 </form> 482 <script type="module" src="/Files/Templates/Designs/Swift/Assets/js/htmx.js"></script> 483 <script type="module"> 484 document.addEventListener('htmx:confirm', (event) => { 485 let filters = event.detail.elt.querySelectorAll('select'); 486 for (var i = 0; i < filters.length; i++) { 487 let input = filters[i]; 488 if (input.name && !input.value) { 489 input.name = ''; 490 } 491 } 492 }); 493 494 document.addEventListener('htmx:beforeOnLoad', (event) => { 495 swift.Scroll.stopIntersectionObserver(); 496 }); 497 498 document.addEventListener('htmx:afterOnLoad', () => { 499 swift.Scroll.hideHeadersOnScroll(); 500 swift.Scroll.handleAlternativeTheme(); 501 }); 502 </script> 503 } 504 else 505 { 506 @gridContent 507 } 508 </div> 509 510 } else { 511 <div class="container"> 512 <div class="alert alert-info" role="alert">@Translate("Sorry. There is nothing to view here")</div> 513 </div> 514 } 515 516 if (!Model.IsCurrentUserAllowed) 517 { 518 int signInPage = GetPageIdByNavigationTag("SignInPage"); 519 int dashboardPage = GetPageIdByNavigationTag("MyAccountDashboardPage"); 520 521 if (!Pageview.IsVisualEditorMode) 522 { 523 if (signInPage != 0) 524 { 525 if (signInPage != Model.ID) { 526 Dynamicweb.Context.Current.Response.Redirect("/Default.aspx?ID=" + signInPage); 527 } else { 528 if (dashboardPage != 0) { 529 Dynamicweb.Context.Current.Response.Redirect("/Default.aspx?ID=" + dashboardPage); 530 } else { 531 Dynamicweb.Context.Current.Response.Redirect("/"); 532 } 533 } 534 } 535 else 536 { 537 <div class="alert alert-dark m-0" role="alert"> 538 <span>@Translate("You do not have access to this page")</span> 539 </div> 540 } 541 } 542 else 543 { 544 <div class="alert alert-dark m-0" role="alert"> 545 <span>@Translate("To work on this page, you must be signed in, in the frontend")</span> 546 </div> 547 } 548 } 549 } 550 551 </main> 552 553 <link rel="stylesheet" href="/Files/Templates/Designs/Swift/Assets/css/glightbox.min.css" /> 554 <script src="/Files/Templates/Designs/Swift/Assets/js/glightbox.min.js"></script> 555 <script> 556 var lightbox = GLightbox({ 557 touchNavigation: true, 558 loop: false, 559 autoplayVideos: true, 560 videosWidth: '80vw', 561 dragAutoSnap: true, 562 plyr: { 563 config: { 564 quality: 720, 565 muted: false, 566 volume: 100, 567 youtube: { noCookie: true, rel: 0, showinfo: 0, iv_load_policy: 3, modestbranding: 1 } 568 } 569 } 570 }); 571 </script> 572 <script> 573 document.addEventListener('DOMContentLoaded', () => { 574 document.querySelectorAll('a').forEach(link => { 575 const href = link.getAttribute('href'); 576 if (href && href.startsWith('https')) { 577 link.setAttribute('target', '_blank'); 578 } else { 579 link.setAttribute('target', '_self'); 580 } 581 }); 582 }); 583 </script> 584 585 @if (renderAsResponsive || !renderMobile) 586 { 587 <footer class="page-footer@(responsiveClassDesktop)" id="page-footer-desktop"> 588 @if (footerDesktopLink != null) 589 { 590 @RenderGrid(footerDesktopLink.PageId) 591 } 592 </footer> 593 } 594 595 @if (renderAsResponsive || renderMobile) 596 { 597 <footer class="page-footer@(responsiveClassMobile)" id="page-footer-mobile"> 598 @if (footerMobileLink != null) 599 { 600 @RenderGrid(footerMobileLink.PageId) 601 } 602 </footer> 603 } 604 605 @* Render any offcanvas menu here *@ 606 @RenderSnippet("offcanvas") 607 608 @{ 609 bool isErpConnectionDown = !Dynamicweb.Core.Converter.ToBoolean(Context.Current.Items["IsWebServiceConnectionAvailable"]); 610 string iconPath = "/Files/Templates/Designs/Swift/Assets/icons/"; 611 } 612 613 @* Language selector modal *@ 614 <div class="modal fade" id="PreferencesModal" tabindex="-1" aria-hidden="true"> 615 <div class="modal-dialog modal-dialog-centered modal-sm" id="PreferencesModalContent"> 616 @* The content here comes from an external request *@ 617 </div> 618 </div> 619 620 @* Toast *@ 621 <div aria-live="polite" aria-atomic="true"> 622 <div class="toast-container position-fixed end-0 p-3" style="top:50px;z-index:1500;"> 623 <div id="notificationToast" class="toast rounded-6 overflow-hidden" role="alert" aria-live="assertive" aria-atomic="true" data-bs-delay="1000"> 624 <div class="toast-body d-flex align-items-end gap-3 theme theme-gray bg-dark text-light"> 625 @ReadFile(iconPath + "check.svg") 626 <div id="notificationToast_Text" class=""></div> 627 </div> 628 </div> 629 </div> 630 </div> 631 632 @* Modal for dynamic content *@ 633 <div class="modal fade js-product" id="DynamicModal" tabindex="-1" aria-hidden="true"> 634 <div class="modal-dialog modal-dialog-centered modal-md"> 635 <div class="modal-content theme light" id="DynamicModalContent"> 636 @* The content here comes from an external request *@ 637 </div> 638 </div> 639 </div> 640 641 @* Offcanvas for dynamic content *@ 642 <div class="offcanvas offcanvas-end theme light" tabindex="-1" id="DynamicOffcanvas"> 643 @* The content here comes from an external request *@ 644 </div> 645 646 @if (Model.Area.Item.GetBoolean("ShowErpDownMessage") && !Dynamicweb.Core.Converter.ToBoolean(Context.Current.Items["IsWebServiceConnectionAvailable"])) 647 { 648 string erpDownMessageTheme = !string.IsNullOrWhiteSpace(Model.Area.Item.GetRawValueString("ErpDownMessageTheme")) ? " theme " + Model.Area.Item.GetRawValueString("ErpDownMessageTheme").Replace(" ", "").Trim().ToLower() : "theme light"; 649 650 <div class="position-fixed bottom-0 end-0 p-3" style="z-index: 1040"> 651 <div class="toast fade show border-0 @erpDownMessageTheme" role="alert" aria-live="assertive" aria-atomic="true"> 652 <div class="toast-header"> 653 <strong class="me-auto">@Translate("Connection down")</strong> 654 <button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button> 655 </div> 656 <div class="toast-body"> 657 @Translate("We are experiencing some connectivity issues. Not all features may be available to you.") 658 </div> 659 </div> 660 </div> 661 } 662 663 @if (miniCartEnabled) 664 { 665 @* Open MiniCart when the cart is updated *@ 666 <script type="module"> 667 document.addEventListener('updated.swift.cart', (event) => { 668 let orderContext = event?.detail?.formData?.get("OrderContext"); 669 updateCartSummary(orderContext); 670 671 @if (offcanvasMiniCartBehaviour == "2" || offcanvasMiniCartBehaviour == "3") { 672 <text>openMiniCartOffcanvas();</text> 673 } 674 }); 675 </script> 676 677 if (offcanvasMiniCartBehaviour == "1" || offcanvasMiniCartBehaviour == "3") 678 { 679 @* Open MiniCart when toggle is clicked *@ 680 <script type="module"> 681 let miniCartToggles = document.querySelectorAll('.mini-cart-quantity'); 682 miniCartToggles?.forEach((toggle) => { 683 toggle.parentElement.addEventListener('click', (event) => { 684 event.preventDefault(); 685 let orderContext = toggle.dataset?.orderContext; 686 updateCartSummary(orderContext); 687 688 openMiniCartOffcanvas(); 689 }); 690 }); 691 </script> 692 } 693 694 <script> 695 696 const updateCartSummary = (orderContext) => { 697 const dynamicOffcanvas = document.getElementById('DynamicOffcanvas'); 698 swift.PageUpdater.UpdateFromUrlInline(event, '/Default.aspx?ID=@(cartSummaryPageId)&CartType=minicart&RequestPageID=@(Pageview.Page.ID)&OrderContext=' + orderContext +'', 'Swift_CartSummary.cshtml', dynamicOffcanvas); 699 }; 700 701 const openMiniCartOffcanvas = () => { 702 const dynamicOffcanvas = document.getElementById('DynamicOffcanvas'); 703 const miniCartOffcanvas = bootstrap.Offcanvas.getOrCreateInstance(dynamicOffcanvas); 704 dynamicOffcanvas.classList.add('overflow-y-auto'); 705 706 if (!miniCartOffcanvas._isShown) { 707 miniCartOffcanvas.show(); 708 hideActiveOffcanvases(miniCartOffcanvas); 709 } 710 }; 711 712 const hideActiveOffcanvases = (miniCartOffcanvas) => { 713 let activeOffcanvases = document.querySelectorAll('.offcanvas.show'); 714 activeOffcanvases?.forEach((offCanvas) => { 715 offCanvas = bootstrap.Offcanvas.getInstance(offCanvas); 716 if (offCanvas !== miniCartOffcanvas) { 717 offCanvas.hide(); 718 } 719 }); 720 }; 721 722 </script> 723 } 724 @if(Pageview.Area.Name?.StartsWith("Xhelter") == false) 725 { 726 @RenderPartial("Components/Custom/CustomLanguageModal.cshtml") 727 } 728 </body> 729 730 </html> 731 732 } 733 else if (Pageview.IsVisualEditorMode) 734 { 735 <head> 736 <title>@Model.Title</title> 737 @* Bootstrap + Swift stylesheet *@ 738 <link href="/Files/Templates/Designs/Swift/Assets/css/styles.css" rel="stylesheet" media="all" type="text/css"> 739 </head> 740 <body class="p-3"> 741 <div class="alert alert-danger" role="alert"> 742 @Translate("Basic Swift setup is needed!") 743 </div> 744 745 @if (brandingPage == null) 746 { 747 <div class="alert alert-warning" role="alert"> 748 @Translate("Please add a Branding page and reference it in website settings") 749 </div> 750 } 751 752 @if (themesParagraphs == null) 753 { 754 <div class="alert alert-warning" role="alert"> 755 @Translate("Please add a Themes collection page and reference it in website settings") 756 </div> 757 } 758 </body> 759 } 760 761 762 @functions { 763 void SetMetaTags() 764 { 765 //Verification Tokens 766 string siteVerificationGoogle = Model.Area.Item.GetString("Google_Site_Verification") != null ? Model.Area.Item.GetString("Google_Site_Verification") : ""; 767 768 //Generic Site Values 769 string openGraphFacebookAppID = Model.Area.Item.GetString("Fb_app_id") != null ? Model.Area.Item.GetString("Fb_app_id") : ""; 770 string openGraphType = Model.Area.Item.GetString("Open_Graph_Type") != null ? Model.Area.Item.GetString("Open_Graph_Type") : ""; 771 string openGraphSiteName = Model.Area.Item.GetString("Open_Graph_Site_Name") != null ? Model.Area.Item.GetString("Open_Graph_Site_Name") : ""; 772 773 string twitterCardSite = Model.Area.Item.GetString("Twitter_Site") != null ? Model.Area.Item.GetString("Twitter_Site") : ""; 774 775 //Page specific values 776 string openGraphSiteTitle = Model.Area.Item.GetString("Open_Graph_Title") != null ? Model.Area.Item.GetString("Open_Graph_Title") : ""; 777 FileViewModel openGraphImage = Model.Area.Item.GetFile("Open_Graph_Image"); 778 string openGraphImageALT = Model.Area.Item.GetString("Open_Graph_Image_ALT") != null ? Model.Area.Item.GetString("Open_Graph_Image_ALT") : ""; 779 string openGraphDescription = Model.Area.Item.GetString("Open_Graph_Description") != null ? Model.Area.Item.GetString("Open_Graph_Description") : ""; 780 781 string twitterCardURL = Model.Area.Item.GetString("Twitter_URL") != null ? Model.Area.Item.GetString("Twitter_URL") : ""; 782 string twitterCardTitle = Model.Area.Item.GetString("Twitter_Title") != null ? Model.Area.Item.GetString("Twitter_Title") : ""; 783 string twitterCardDescription = Model.Area.Item.GetString("Twitter_Description") != null ? Model.Area.Item.GetString("Twitter_Description") : ""; 784 FileViewModel twitterCardImage = Model.Area.Item.GetFile("Twitter_Image"); 785 string twitterCardImageALT = Model.Area.Item.GetString("Twitter_Image_ALT") != null ? Model.Area.Item.GetString("Twitter_Image_ALT") : ""; 786 string topImage = Pageview.Page.TopImage.StartsWith("/Files", StringComparison.OrdinalIgnoreCase) ? Pageview.Page.TopImage : $"/Files{Pageview.Page.TopImage}"; 787 788 if (string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString["ProductID"])) 789 { 790 if (!string.IsNullOrEmpty(Model.Description)) 791 { 792 Pageview.Meta.AddTag($"<meta property=\"og:description\" content=\"{Model.Description}\">"); 793 } 794 else 795 { 796 Pageview.Meta.AddTag($"<meta property=\"og:description\" content=\"{openGraphDescription}\">"); 797 } 798 799 if (!string.IsNullOrEmpty(Pageview.Page.TopImage)) 800 { 801 Pageview.Meta.AddTag($"<meta property=\"og:image\" content=\"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}{topImage}\">"); 802 Pageview.Meta.AddTag($"<meta property=\"og:image:secure_url\" content=\"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}{topImage}\">"); 803 } 804 else if (openGraphImage != null) 805 { 806 Pageview.Meta.AddTag($"<meta property=\"og:image\" content=\"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}{openGraphImage.Path}\">"); 807 Pageview.Meta.AddTag($"<meta property=\"og:image:secure_url\" content=\"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}{openGraphImage.Path}\">"); 808 } 809 810 if (!string.IsNullOrEmpty(openGraphImageALT)) 811 { 812 Pageview.Meta.AddTag($"<meta property=\"og:image:alt\" content=\"{openGraphImageALT}\">"); 813 } 814 if (!string.IsNullOrEmpty(twitterCardDescription)) 815 { 816 Pageview.Meta.AddTag("twitter:description", twitterCardDescription); 817 } 818 819 if (!string.IsNullOrEmpty(Pageview.Page.TopImage)) 820 { 821 Pageview.Meta.AddTag("twitter:image", $"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}{topImage}"); 822 } 823 else if (twitterCardImage != null) 824 { 825 Pageview.Meta.AddTag("twitter:image", $"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}{openGraphImage.Path}"); 826 } 827 828 if (!string.IsNullOrEmpty(twitterCardImageALT)) 829 { 830 Pageview.Meta.AddTag("twitter:image:alt", twitterCardImageALT); 831 } 832 } 833 834 if (!string.IsNullOrEmpty(siteVerificationGoogle)) 835 { 836 Pageview.Meta.AddTag("google-site-verification", siteVerificationGoogle); 837 } 838 839 if (!string.IsNullOrEmpty(openGraphFacebookAppID)) 840 { 841 Pageview.Meta.AddTag($"<meta property=\"fb:app_id\" content=\"{openGraphFacebookAppID}\">"); 842 } 843 844 if (!string.IsNullOrEmpty(openGraphType)) 845 { 846 Pageview.Meta.AddTag($"<meta property=\"og:type\" content=\"{openGraphType}\">"); 847 } 848 849 if (!string.IsNullOrEmpty(openGraphSiteName)) 850 { 851 Pageview.Meta.AddTag($"<meta property=\"og:url\" content=\"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}{Pageview.SearchFriendlyUrl}\">"); 852 } 853 854 if (!string.IsNullOrEmpty(openGraphSiteName)) 855 { 856 Pageview.Meta.AddTag($"<meta property=\"og:site_name\" content=\"{openGraphSiteName}\">"); 857 } 858 859 if (!string.IsNullOrEmpty(Model.Title)) 860 { 861 Pageview.Meta.AddTag($"<meta property=\"og:title\" content=\"{Model.Title}\">"); 862 } 863 else 864 { 865 Pageview.Meta.AddTag($"<meta property=\"og:title\" content=\"{openGraphSiteTitle}\">"); 866 } 867 868 if (!string.IsNullOrEmpty(twitterCardSite)) 869 { 870 Pageview.Meta.AddTag("twitter:site", twitterCardSite); 871 } 872 873 if (!string.IsNullOrEmpty(twitterCardURL)) 874 { 875 Pageview.Meta.AddTag("twitter:url", twitterCardURL); 876 } 877 878 if (!string.IsNullOrEmpty(twitterCardTitle)) 879 { 880 Pageview.Meta.AddTag("twitter:title", twitterCardTitle); 881 } 882 } 883 } 884