Error executing template "Designs/Swift/_parsed/Swift_Page.parsed.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at CompiledRazorTemplates.Dynamic.RazorEngine_6f8c3bd6d7a04df9b821588a84fdfb42.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 132 var cssStyleFileInfo = new System.IO.FileInfo(Dynamicweb.Core.SystemInformation.MapPath("/Files/Templates/Designs/Swift/Assets/css/styles.css")); 133 var jsFileInfo = new System.IO.FileInfo(Dynamicweb.Core.SystemInformation.MapPath("/Files/Templates/Designs/Swift/Assets/js/scripts.js")); 134 var jsMainFileInfo = new System.IO.FileInfo(Dynamicweb.Core.SystemInformation.MapPath("/Files/Templates/Designs/Swift/Assets/js/main.js")); 135 136 string masterTheme = !string.IsNullOrWhiteSpace(Model.Area.Item.GetRawValueString("Theme")) ? " theme " + Model.Area.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 137 138 string favicon = Model.Area.Item.GetRawValueString("Favicon", "/Files/Templates/Designs/Swift/Assets/Images/favicon.png"); 139 string appleTouchIcon = Model.Area.Item.GetRawValueString("AppleTouchIcon", "/Files/Templates/Designs/Swift/Assets/Images/apple-touch-icon.png"); 140 141 string headerCssClass = "sticky-top"; 142 bool movePageBehind = false; 143 144 if (Model.PropertyItem != null) 145 { 146 headerCssClass = Model.PropertyItem.GetRawValueString("MoveThisPageBehindTheHeader", "sticky-top"); 147 movePageBehind = headerCssClass == "fixed-top" && !Pageview.IsVisualEditorMode ? true : false; 148 } 149 150 headerCssClass = headerCssClass == "" ? "sticky-top" : headerCssClass; 151 headerCssClass = Pageview.IsVisualEditorMode ? "" : headerCssClass; 152 153 string googleTagManagerID = Model.Area.Item.GetString("GoogleTagManagerID").Trim(); 154 string googleAnalyticsMeasurementID = Model.Area.Item.GetString("GoogleAnalyticsMeasurementID").Trim(); 155 156 bool allowTracking = AllowTracking(); 157 158 Dynamicweb.Context.Current.Response.AddHeader("link", $"</Files/Templates/Designs/Swift/Assets/css/styles.css?{cssStyleFileInfo.LastWriteTime.Ticks}>; rel=preload; as=style;"); 159 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;"); 160 Dynamicweb.Context.Current.Response.AddHeader("link", $"</Files/Templates/Designs/Swift/Assets/js/scripts.js?{jsFileInfo.LastWriteTime.Ticks}>; rel=preload; as=script;"); 161 Dynamicweb.Context.Current.Response.AddHeader("link", $"</Files/Templates/Designs/Swift/Assets/js/main.js?{jsMainFileInfo.LastWriteTime.Ticks}>; rel=preload; as=script;"); 162 163 164 SetMetaTags(); 165 166 List<Dynamicweb.Content.Page> languages = new List<Dynamicweb.Content.Page>(); 167 168 var masterPage = Pageview.Area.IsMaster ? Pageview.Page : Pageview.Page.MasterPage; 169 languages.Add(masterPage); 170 if (masterPage?.Languages != null) 171 { 172 foreach (var language in masterPage.Languages) 173 { 174 languages.Add(language); 175 } 176 } 177 178 Uri url = Dynamicweb.Context.Current.Request.Url; 179 string hostName = url.Host; 180 181 <!doctype html> 182 <html lang="@Pageview.Area.CultureInfo.TwoLetterISOLanguageName"> 183 <head> 184 <!-- @swiftVersion --> 185 @* Required meta tags *@ 186 <meta charset="utf-8"> 187 <meta name="viewport" content="height=device-height, width=device-width, initial-scale=1.0"> 188 <link rel="shortcut icon" href="@favicon"> 189 <link rel="apple-touch-icon" href="@appleTouchIcon"> 190 191 @Model.MetaTags 192 193 @{ 194 var alreadyWrittenTwoletterIsos = new List<string>(); 195 @* Languages meta data *@ 196 foreach (var language in languages) 197 { 198 hostName = url.Host; 199 if (language?.Area != null) 200 { 201 if (language.Area?.MasterArea != null && !string.IsNullOrEmpty(language.Area.MasterArea.DomainLock)) 202 { 203 hostName = language.Area.MasterArea.DomainLock; //dk.domain.com or dk-domain.dk 204 } 205 if (language != null && language.Area != null && language.Published && language.Area.Active && language.Area.Published) 206 { 207 if (!string.IsNullOrEmpty(language.Area.DomainLock)) 208 { 209 hostName = language.Area.DomainLock; //dk.domain.com or dk-domain.dk 210 } 211 string querystring = $"Default.aspx?ID={language.ID}"; 212 if (!string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString["GroupID"])) 213 { 214 querystring += $"&GroupID={Dynamicweb.Context.Current.Request.QueryString["GroupID"]}"; 215 } 216 if (!string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString["ProductID"])) 217 { 218 querystring += $"&ProductID={Dynamicweb.Context.Current.Request.QueryString["ProductID"]}"; 219 } 220 if (!string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString["VariantID"])) 221 { 222 querystring += $"&VariantID={Dynamicweb.Context.Current.Request.QueryString["VariantID"]}"; 223 } 224 225 string friendlyUrl = Dynamicweb.Frontend.SearchEngineFriendlyURLs.GetFriendlyUrl(querystring); 226 if (language.Area.RedirectFirstPage && language.ParentPageId == 0 && language.Sort == 1) 227 { 228 friendlyUrl = "/"; 229 } 230 string href = $"{url.Scheme}://{hostName}{friendlyUrl}"; 231 232 233 <link rel="alternate" hreflang="@language.Area.CultureInfo.Name.ToLower()" href="@href"> 234 if (!alreadyWrittenTwoletterIsos.Contains(language.Area.CultureInfo.TwoLetterISOLanguageName)) 235 { 236 alreadyWrittenTwoletterIsos.Add(language.Area.CultureInfo.TwoLetterISOLanguageName); 237 <link rel="alternate" hreflang="@language.Area.CultureInfo.TwoLetterISOLanguageName.ToLower()" href="@href"> 238 } 239 } 240 } 241 } 242 } 243 244 <title>@Model.Title</title> 245 @* Bootstrap + Swift stylesheet *@ 246 <link href="/Files/Templates/Designs/Swift/Assets/css/styles.css?@cssStyleFileInfo.LastWriteTime.Ticks" rel="stylesheet" media="all" type="text/css"> 247 248 @if (disableWideBreakpoints != "disableBoth") 249 { 250 <style> 251 @@media ( min-width: 1600px ) { 252 .container-xxl, 253 .container-xl, 254 .container-lg, 255 .container-md, 256 .container-sm, 257 .container { 258 max-width: 1520px; 259 } 260 } 261 </style> 262 263 264 265 if (disableWideBreakpoints != "disableUltraWideOnly") 266 { 267 <style> 268 @@media ( min-width: 1920px ) { 269 .container-xxl, 270 .container-xl, 271 .container-lg, 272 .container-md, 273 .container-sm, 274 .container { 275 max-width: 1820px; 276 } 277 } 278 </style> 279 } 280 } 281 282 @* Branding and Themes min stylesheet *@ 283 <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"> 284 <script src="/Files/Templates/Designs/Swift/Assets/js/scripts.js?@jsFileInfo.LastWriteTime.Ticks"></script> 285 <script src="/Files/Templates/Designs/Swift/Assets/js/main.js?@jsMainFileInfo.LastWriteTime.Ticks"></script> 286 <script type="module"> 287 swift.Scroll.hideHeadersOnScroll(); 288 swift.Scroll.handleAlternativeTheme(); 289 290 //Only load if AOS 291 const aosColumns = document.querySelectorAll('[data-aos]'); 292 if (aosColumns.length > 0) { 293 swift.AssetLoader.Load('/Files/Templates/Designs/Swift/Assets/js/aos.js?@jsFileInfo.LastWriteTime.Ticks', 'js'); 294 document.addEventListener('load.swift.assetloader', function () { 295 AOS.init({ duration: 400, delay: 100, easing: 'ease-in-out', mirror: false, disable: window.matchMedia('(prefers-reduced-motion: reduce)') }); 296 }); 297 } 298 </script> 299 300 @* Google gtag method - always include even if it is not used for anything *@ 301 <script> 302 window.dataLayer = window.dataLayer || []; 303 function gtag() { 304 //dataLayer.push(arguments); 305 if(arguments[2].items) { 306 dataLayer.push({ ecommerce: null }); 307 dataLayer.push({ 308 event: arguments[1], 309 ecommerce: arguments[2] 310 }); 311 } else { 312 dataLayer.push(arguments); 313 } 314 } 315 </script> 316 @* Google tag manager *@ 317 @if (!string.IsNullOrWhiteSpace(googleTagManagerID)) 318 { 319 <script> 320 gtag('consent', 'default', { 321 'ad_storage': 'denied', 322 'ad_user_data': 'denied', 323 'ad_personalization': 'denied', 324 'analytics_storage': 'denied' 325 }); 326 </script> 327 <script> 328 (function (w, d, s, l, i) { 329 w[l] = w[l] || []; w[l].push({ 330 'gtm.start': 331 new Date().getTime(), event: 'gtm.js' 332 }); var f = d.getElementsByTagName(s)[0], 333 j = d.createElement(s), dl = l != 'dataLayer' ? '&l=' + l : ''; j.async = true; j.src = 334 'https://www.googletagmanager.com/gtm.js?id=' + i + dl; f.parentNode.insertBefore(j, f); 335 })(window, document, 'script', 'dataLayer', '@(googleTagManagerID)'); 336 </script> 337 if (allowTracking) 338 { 339 string adConsent = GetCookieOptInPermission("Marketing"); 340 string analyticsConsent = GetCookieOptInPermission("Statistical"); 341 <script> 342 gtag('consent', 'update', { 343 'ad_storage': '@adConsent', 344 'ad_user_data': '@adConsent', 345 'ad_personalization': '@adConsent', 346 'analytics_storage': '@analyticsConsent' 347 }); 348 </script> 349 } 350 } 351 352 @if (!string.IsNullOrWhiteSpace(googleAnalyticsMeasurementID) && allowTracking) 353 { 354 var GoogleAnalyticsDebugMode = ""; 355 356 if (Model.Area.Item.GetBoolean("EnableGoogleAnalyticsDebugMode")) 357 { 358 GoogleAnalyticsDebugMode = ", {'debug_mode': true}"; 359 } 360 361 <script async src="https://www.googletagmanager.com/gtag/js?id=@googleAnalyticsMeasurementID"></script> 362 <script> 363 gtag('js', new Date()); 364 gtag('config', '@googleAnalyticsMeasurementID'@GoogleAnalyticsDebugMode); 365 </script> 366 } 367 368 @if (!string.IsNullOrWhiteSpace(customHeaderInclude)) 369 { 370 @RenderPartial($"Components/Custom/{customHeaderInclude}") 371 } 372 </head> 373 <body class="brand @(masterTheme)" id="page@(Model.ID)"> 374 375 @* Google tag manager *@ 376 @if (!string.IsNullOrWhiteSpace(googleTagManagerID) && allowTracking) 377 { 378 <noscript> 379 <iframe src="https://www.googletagmanager.com/ns.html?id=@(googleTagManagerID)" 380 height="0" width="0" style="display:none;visibility:hidden"></iframe> 381 </noscript> 382 } 383 384 @if (renderAsResponsive || !renderMobile) 385 { 386 var IsCatalogPage = Pageview.Page.ItemType == "Swift_CatalogPage"; 387 388 <header class="page-header @headerCssClass top-0@(responsiveClassDesktop)" id="page-header-desktop"> 389 @if (IsCatalogPage) 390 { 391 // Current page path. Page Id and title 392 var PagePath = Pageview.Page.GetPath() 393 .Select(a => new KeyValuePair<int, string>(a.ID, a.MenuText)) 394 .ToDictionary(x => x.Key, x => x.Value); 395 396 var CatalogHeader = Dynamicweb.Content.Services.Pages.GetPageByNavigationTag(Pageview.Area.ID, "CatalogHeader"); 397 var RootpathBrandname = PagePath.Skip(3).FirstOrDefault().Value; 398 var BrandName = RootpathBrandname?.ToLower() switch 399 { 400 "outwell" => "Swift_styles_3", 401 "robens" => "Swift_styles_4", 402 "easy camp" => "Swift_styles_2", 403 _ => "" 404 }; 405 <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"> 406 @RenderGrid(CatalogHeader.ID) 407 } else 408 { 409 if (headerDesktopLink != null) 410 { 411 @RenderGrid(headerDesktopLink.PageId) 412 } 413 } 414 </header> 415 } 416 417 @if ((renderAsResponsive || renderMobile)) 418 { 419 <header class="page-header @headerCssClass top-0@(responsiveClassMobile)" id="page-header-mobile"> 420 @if (headerMobileLink != null) 421 { 422 @RenderGrid(headerMobileLink.PageId) 423 } 424 </header> 425 } 426 427 <div data-intersect></div> 428 429 <main id="content" @(schemaOrgType)> 430 @inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.PageViewModel> @using System @using Dynamicweb.Ecommerce.ProductCatalog @{ string productIdFromUrl = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString.Get("ProductID")) ? Dynamicweb.Context.Current.Request.QueryString.Get("ProductID") : string.Empty; bool isProductDetail = !string.IsNullOrEmpty(productIdFromUrl) && Pageview.Page.NavigationTag.ToLower() == "shop"; bool isArticlePagePage = Model.ItemType == "Swift_Article"; bool isArticleListPage = Model.ItemType == "Swift_ArticleListPage"; string schemaOrgProp = string.Empty; if(isArticlePagePage) { schemaOrgProp = "itemprop=\"articleBody\""; } string theme = ""; string gridContent = ""; if (Model.PropertyItem != null) { theme = !string.IsNullOrWhiteSpace(Model.PropertyItem.GetRawValueString("Theme")) ? "theme " + Model.PropertyItem.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; } if (Model.Item != null || Pageview.IsVisualEditorMode) { if (!isProductDetail) { gridContent = Model.Grid("Grid", "Grid", "default:true;sort:1", "Page"); } else { var productObject = Dynamicweb.Ecommerce.Services.Products.GetProductById(productIdFromUrl, "", Pageview.Area.EcomLanguageId); var detailPage = Dynamicweb.Ecommerce.Services.ProductGroups.GetGroup(productObject.PrimaryGroupId)?.Meta.PrimaryPage ?? string.Empty; var detailPageId = detailPage != string.Empty ? Convert.ToInt16(detailPage.Substring(detailPage.LastIndexOf('=') + 1)) : GetPageIdByNavigationTag("ProductDetailPage"); @RenderGrid(detailPageId) } } bool doNotRenderPage = false; //Check if we are on the poduct detail page, and if there is data to render ProductViewModel product = new ProductViewModel(); if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) { product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; if (string.IsNullOrEmpty(product.Id)) { doNotRenderPage = true; } } if(!string.IsNullOrWhiteSpace(productIdFromUrl)) { <script> gtag("event", "view_item", { currency: "@product.Price.CurrencyCode", value: @PriceViewModelExtensions.ToStringInvariant(product.Price), items: [ { item_id: "@product.Number", item_name: "@Dynamicweb.Core.Encoders.HtmlEncoder.JavaScriptStringEncode(product.Name)", currency: "@product.Price.CurrencyCode", price: @PriceViewModelExtensions.ToStringInvariant(product.Price) } ] }); </script> } //Render the page if (!doNotRenderPage) { string itemIdentifier = Model?.Item?.SystemName != null ? "item_" + Model.Item.SystemName.ToLower() : "item_Swift_Page"; if (Pageview.IsVisualEditorMode) { @Model.Placeholder("dwcontent", "content", "default:true;sort:1") } <div class="@theme @itemIdentifier" @schemaOrgProp> @if (isArticleListPage) { 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\""; <form @hx id="ArticleFacetForm"> @gridContent </form> <script type="module" src="/Files/Templates/Designs/Swift/Assets/js/htmx.js"></script> <script type="module"> document.addEventListener('htmx:confirm', (event) => { let filters = event.detail.elt.querySelectorAll('select'); for (var i = 0; i < filters.length; i++) { let input = filters[i]; if (input.name && !input.value) { input.name = ''; } } }); document.addEventListener('htmx:beforeOnLoad', (event) => { swift.Scroll.stopIntersectionObserver(); }); document.addEventListener('htmx:afterOnLoad', () => { swift.Scroll.hideHeadersOnScroll(); swift.Scroll.handleAlternativeTheme(); }); </script> } else { @gridContent } </div> } else { <div class="container"> <div class="alert alert-info" role="alert">@Translate("Sorry. There is nothing to view here")</div> </div> } if (!Model.IsCurrentUserAllowed) { int signInPage = GetPageIdByNavigationTag("SignInPage"); int dashboardPage = GetPageIdByNavigationTag("MyAccountDashboardPage"); if (!Pageview.IsVisualEditorMode) { if (signInPage != 0) { if (signInPage != Model.ID) { Dynamicweb.Context.Current.Response.Redirect("/Default.aspx?ID=" + signInPage); } else { if (dashboardPage != 0) { Dynamicweb.Context.Current.Response.Redirect("/Default.aspx?ID=" + dashboardPage); } else { Dynamicweb.Context.Current.Response.Redirect("/"); } } } else { <div class="alert alert-dark m-0" role="alert"> <span>@Translate("You do not have access to this page")</span> </div> } } else { <div class="alert alert-dark m-0" role="alert"> <span>@Translate("To work on this page, you must be signed in, in the frontend")</span> </div> } } } 431 </main> 432 433 <link rel="stylesheet" href="/Files/Templates/Designs/Swift/Assets/css/glightbox.min.css" /> 434 <script src="/Files/Templates/Designs/Swift/Assets/js/glightbox.min.js"></script> 435 <script> 436 var lightbox = GLightbox({ 437 touchNavigation: true, 438 loop: false, 439 autoplayVideos: true, 440 videosWidth: '100vw', 441 plyr: { 442 config: { 443 quality: 720, 444 muted: false, 445 volume: 100, 446 youtube: { noCookie: true, rel: 0, showinfo: 0, iv_load_policy: 3, modestbranding: 1 } 447 } 448 } 449 }); 450 </script> 451 <script> 452 document.addEventListener('DOMContentLoaded', () => { 453 document.querySelectorAll('a').forEach(link => { 454 const href = link.getAttribute('href'); 455 if (href && href.startsWith('https')) { 456 link.setAttribute('target', '_blank'); 457 } else { 458 link.setAttribute('target', '_self'); 459 } 460 }); 461 }); 462 </script> 463 464 @if (renderAsResponsive || !renderMobile) 465 { 466 <footer class="page-footer@(responsiveClassDesktop)" id="page-footer-desktop"> 467 @if (footerDesktopLink != null) 468 { 469 @RenderGrid(footerDesktopLink.PageId) 470 } 471 </footer> 472 } 473 474 @if (renderAsResponsive || renderMobile) 475 { 476 <footer class="page-footer@(responsiveClassMobile)" id="page-footer-mobile"> 477 @if (footerMobileLink != null) 478 { 479 @RenderGrid(footerMobileLink.PageId) 480 } 481 </footer> 482 } 483 484 @* Render any offcanvas menu here *@ 485 @RenderSnippet("offcanvas") 486 487 @{ 488 bool isErpConnectionDown = !Dynamicweb.Core.Converter.ToBoolean(Context.Current.Items["IsWebServiceConnectionAvailable"]); 489 string iconPath = "/Files/Templates/Designs/Swift/Assets/icons/"; 490 } 491 492 @* Language selector modal *@ 493 <div class="modal fade" id="PreferencesModal" tabindex="-1" aria-hidden="true"> 494 <div class="modal-dialog modal-dialog-centered modal-sm" id="PreferencesModalContent"> 495 @* The content here comes from an external request *@ 496 </div> 497 </div> 498 499 @* Toast *@ 500 <div aria-live="polite" aria-atomic="true"> 501 <div class="toast-container position-fixed end-0 p-3" style="top:50px;z-index:1500;"> 502 <div id="notificationToast" class="toast rounded-6 overflow-hidden" role="alert" aria-live="assertive" aria-atomic="true" data-bs-delay="1000"> 503 <div class="toast-body d-flex align-items-end gap-3 theme theme-gray bg-dark text-light"> 504 @ReadFile(iconPath + "check.svg") 505 <div id="notificationToast_Text" class=""></div> 506 </div> 507 </div> 508 </div> 509 </div> 510 511 @* Modal for dynamic content *@ 512 <div class="modal fade js-product" id="DynamicModal" tabindex="-1" aria-hidden="true"> 513 <div class="modal-dialog modal-dialog-centered modal-md"> 514 <div class="modal-content theme light" id="DynamicModalContent"> 515 @* The content here comes from an external request *@ 516 </div> 517 </div> 518 </div> 519 520 @* Offcanvas for dynamic content *@ 521 <div class="offcanvas offcanvas-end theme light" tabindex="-1" id="DynamicOffcanvas"> 522 @* The content here comes from an external request *@ 523 </div> 524 525 @if (Model.Area.Item.GetBoolean("ShowErpDownMessage") && !Dynamicweb.Core.Converter.ToBoolean(Context.Current.Items["IsWebServiceConnectionAvailable"])) 526 { 527 string erpDownMessageTheme = !string.IsNullOrWhiteSpace(Model.Area.Item.GetRawValueString("ErpDownMessageTheme")) ? " theme " + Model.Area.Item.GetRawValueString("ErpDownMessageTheme").Replace(" ", "").Trim().ToLower() : "theme light"; 528 529 <div class="position-fixed bottom-0 end-0 p-3" style="z-index: 1040"> 530 <div class="toast fade show border-0 @erpDownMessageTheme" role="alert" aria-live="assertive" aria-atomic="true"> 531 <div class="toast-header"> 532 <strong class="me-auto">@Translate("Connection down")</strong> 533 <button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button> 534 </div> 535 <div class="toast-body"> 536 @Translate("We are experiencing some connectivity issues. Not all features may be available to you.") 537 </div> 538 </div> 539 </div> 540 } 541 542 @if (miniCartEnabled) 543 { 544 @* Open MiniCart when the cart is updated *@ 545 <script type="module"> 546 document.addEventListener('updated.swift.cart', (event) => { 547 let orderContext = event?.detail?.formData?.get("OrderContext"); 548 updateCartSummary(orderContext); 549 550 @if (offcanvasMiniCartBehaviour == "2" || offcanvasMiniCartBehaviour == "3") { 551 <text>openMiniCartOffcanvas();</text> 552 } 553 }); 554 </script> 555 556 if (offcanvasMiniCartBehaviour == "1" || offcanvasMiniCartBehaviour == "3") 557 { 558 @* Open MiniCart when toggle is clicked *@ 559 <script type="module"> 560 let miniCartToggles = document.querySelectorAll('.mini-cart-quantity'); 561 miniCartToggles?.forEach((toggle) => { 562 toggle.parentElement.addEventListener('click', (event) => { 563 event.preventDefault(); 564 let orderContext = toggle.dataset?.orderContext; 565 updateCartSummary(orderContext); 566 567 openMiniCartOffcanvas(); 568 }); 569 }); 570 </script> 571 } 572 573 <script> 574 575 const updateCartSummary = (orderContext) => { 576 const dynamicOffcanvas = document.getElementById('DynamicOffcanvas'); 577 swift.PageUpdater.UpdateFromUrlInline(event, '/Default.aspx?ID=@(cartSummaryPageId)&CartType=minicart&RequestPageID=@(Pageview.Page.ID)&OrderContext=' + orderContext +'', 'Swift_CartSummary.cshtml', dynamicOffcanvas); 578 }; 579 580 const openMiniCartOffcanvas = () => { 581 const dynamicOffcanvas = document.getElementById('DynamicOffcanvas'); 582 const miniCartOffcanvas = bootstrap.Offcanvas.getOrCreateInstance(dynamicOffcanvas); 583 dynamicOffcanvas.classList.add('overflow-y-auto'); 584 585 if (!miniCartOffcanvas._isShown) { 586 miniCartOffcanvas.show(); 587 hideActiveOffcanvases(miniCartOffcanvas); 588 } 589 }; 590 591 const hideActiveOffcanvases = (miniCartOffcanvas) => { 592 let activeOffcanvases = document.querySelectorAll('.offcanvas.show'); 593 activeOffcanvases?.forEach((offCanvas) => { 594 offCanvas = bootstrap.Offcanvas.getInstance(offCanvas); 595 if (offCanvas !== miniCartOffcanvas) { 596 offCanvas.hide(); 597 } 598 }); 599 }; 600 601 </script> 602 } 603 604 </body> 605 606 </html> 607 608 } 609 else if (Pageview.IsVisualEditorMode) 610 { 611 <head> 612 <title>@Model.Title</title> 613 @* Bootstrap + Swift stylesheet *@ 614 <link href="/Files/Templates/Designs/Swift/Assets/css/styles.css" rel="stylesheet" media="all" type="text/css"> 615 </head> 616 <body class="p-3"> 617 <div class="alert alert-danger" role="alert"> 618 @Translate("Basic Swift setup is needed!") 619 </div> 620 621 @if (brandingPage == null) 622 { 623 <div class="alert alert-warning" role="alert"> 624 @Translate("Please add a Branding page and reference it in website settings") 625 </div> 626 } 627 628 @if (themesParagraphs == null) 629 { 630 <div class="alert alert-warning" role="alert"> 631 @Translate("Please add a Themes collection page and reference it in website settings") 632 </div> 633 } 634 </body> 635 } 636 637 638 @functions { 639 void SetMetaTags() 640 { 641 //Verification Tokens 642 string siteVerificationGoogle = Model.Area.Item.GetString("Google_Site_Verification") != null ? Model.Area.Item.GetString("Google_Site_Verification") : ""; 643 644 //Generic Site Values 645 string openGraphFacebookAppID = Model.Area.Item.GetString("Fb_app_id") != null ? Model.Area.Item.GetString("Fb_app_id") : ""; 646 string openGraphType = Model.Area.Item.GetString("Open_Graph_Type") != null ? Model.Area.Item.GetString("Open_Graph_Type") : ""; 647 string openGraphSiteName = Model.Area.Item.GetString("Open_Graph_Site_Name") != null ? Model.Area.Item.GetString("Open_Graph_Site_Name") : ""; 648 649 string twitterCardSite = Model.Area.Item.GetString("Twitter_Site") != null ? Model.Area.Item.GetString("Twitter_Site") : ""; 650 651 //Page specific values 652 string openGraphSiteTitle = Model.Area.Item.GetString("Open_Graph_Title") != null ? Model.Area.Item.GetString("Open_Graph_Title") : ""; 653 FileViewModel openGraphImage = Model.Area.Item.GetFile("Open_Graph_Image"); 654 string openGraphImageALT = Model.Area.Item.GetString("Open_Graph_Image_ALT") != null ? Model.Area.Item.GetString("Open_Graph_Image_ALT") : ""; 655 string openGraphDescription = Model.Area.Item.GetString("Open_Graph_Description") != null ? Model.Area.Item.GetString("Open_Graph_Description") : ""; 656 657 string twitterCardURL = Model.Area.Item.GetString("Twitter_URL") != null ? Model.Area.Item.GetString("Twitter_URL") : ""; 658 string twitterCardTitle = Model.Area.Item.GetString("Twitter_Title") != null ? Model.Area.Item.GetString("Twitter_Title") : ""; 659 string twitterCardDescription = Model.Area.Item.GetString("Twitter_Description") != null ? Model.Area.Item.GetString("Twitter_Description") : ""; 660 FileViewModel twitterCardImage = Model.Area.Item.GetFile("Twitter_Image"); 661 string twitterCardImageALT = Model.Area.Item.GetString("Twitter_Image_ALT") != null ? Model.Area.Item.GetString("Twitter_Image_ALT") : ""; 662 string topImage = Pageview.Page.TopImage.StartsWith("/Files", StringComparison.OrdinalIgnoreCase) ? Pageview.Page.TopImage : $"/Files{Pageview.Page.TopImage}"; 663 664 if (string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString["ProductID"])) 665 { 666 if (!string.IsNullOrEmpty(Model.Description)) 667 { 668 Pageview.Meta.AddTag($"<meta property=\"og:description\" content=\"{Model.Description}\">"); 669 } 670 else 671 { 672 Pageview.Meta.AddTag($"<meta property=\"og:description\" content=\"{openGraphDescription}\">"); 673 } 674 675 if (!string.IsNullOrEmpty(Pageview.Page.TopImage)) 676 { 677 Pageview.Meta.AddTag($"<meta property=\"og:image\" content=\"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}{topImage}\">"); 678 Pageview.Meta.AddTag($"<meta property=\"og:image:secure_url\" content=\"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}{topImage}\">"); 679 } 680 else if (openGraphImage != null) 681 { 682 Pageview.Meta.AddTag($"<meta property=\"og:image\" content=\"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}{openGraphImage.Path}\">"); 683 Pageview.Meta.AddTag($"<meta property=\"og:image:secure_url\" content=\"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}{openGraphImage.Path}\">"); 684 } 685 686 if (!string.IsNullOrEmpty(openGraphImageALT)) 687 { 688 Pageview.Meta.AddTag($"<meta property=\"og:image:alt\" content=\"{openGraphImageALT}\">"); 689 } 690 if (!string.IsNullOrEmpty(twitterCardDescription)) 691 { 692 Pageview.Meta.AddTag("twitter:description", twitterCardDescription); 693 } 694 695 if (!string.IsNullOrEmpty(Pageview.Page.TopImage)) 696 { 697 Pageview.Meta.AddTag("twitter:image", $"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}{topImage}"); 698 } 699 else if (twitterCardImage != null) 700 { 701 Pageview.Meta.AddTag("twitter:image", $"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}{openGraphImage.Path}"); 702 } 703 704 if (!string.IsNullOrEmpty(twitterCardImageALT)) 705 { 706 Pageview.Meta.AddTag("twitter:image:alt", twitterCardImageALT); 707 } 708 } 709 710 if (!string.IsNullOrEmpty(siteVerificationGoogle)) 711 { 712 Pageview.Meta.AddTag("google-site-verification", siteVerificationGoogle); 713 } 714 715 if (!string.IsNullOrEmpty(openGraphFacebookAppID)) 716 { 717 Pageview.Meta.AddTag($"<meta property=\"fb:app_id\" content=\"{openGraphFacebookAppID}\">"); 718 } 719 720 if (!string.IsNullOrEmpty(openGraphType)) 721 { 722 Pageview.Meta.AddTag($"<meta property=\"og:type\" content=\"{openGraphType}\">"); 723 } 724 725 if (!string.IsNullOrEmpty(openGraphSiteName)) 726 { 727 Pageview.Meta.AddTag($"<meta property=\"og:url\" content=\"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}{Pageview.SearchFriendlyUrl}\">"); 728 } 729 730 if (!string.IsNullOrEmpty(openGraphSiteName)) 731 { 732 Pageview.Meta.AddTag($"<meta property=\"og:site_name\" content=\"{openGraphSiteName}\">"); 733 } 734 735 if (!string.IsNullOrEmpty(Model.Title)) 736 { 737 Pageview.Meta.AddTag($"<meta property=\"og:title\" content=\"{Model.Title}\">"); 738 } 739 else 740 { 741 Pageview.Meta.AddTag($"<meta property=\"og:title\" content=\"{openGraphSiteTitle}\">"); 742 } 743 744 if (!string.IsNullOrEmpty(twitterCardSite)) 745 { 746 Pageview.Meta.AddTag("twitter:site", twitterCardSite); 747 } 748 749 if (!string.IsNullOrEmpty(twitterCardURL)) 750 { 751 Pageview.Meta.AddTag("twitter:url", twitterCardURL); 752 } 753 754 if (!string.IsNullOrEmpty(twitterCardTitle)) 755 { 756 Pageview.Meta.AddTag("twitter:title", twitterCardTitle); 757 } 758 } 759 } 760