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