Error executing template "Designs/Swift/Swift_Page.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
at CompiledRazorTemplates.Dynamic.RazorEngine_2fbddaf47b92494d8f63b73dd9b89fdf.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 } else {
556 <div class="container py-5">
557 <div class="alert alert-info" role="alert">@Translate("Sorry. There is nothing to view here")</div>
558 </div>
559 }
560
561 if (!Model.IsCurrentUserAllowed)
562 {
563 int signInPage = GetPageIdByNavigationTag("SignInPage");
564 int dashboardPage = GetPageIdByNavigationTag("MyAccountDashboardPage");
565
566 if (!Pageview.IsVisualEditorMode)
567 {
568 if (signInPage != 0)
569 {
570 if (signInPage != Model.ID) {
571 Dynamicweb.Context.Current.Response.Redirect("/Default.aspx?ID=" + signInPage);
572 } else {
573 if (dashboardPage != 0) {
574 Dynamicweb.Context.Current.Response.Redirect("/Default.aspx?ID=" + dashboardPage);
575 } else {
576 Dynamicweb.Context.Current.Response.Redirect("/");
577 }
578 }
579 }
580 else
581 {
582 <div class="alert alert-dark m-0" role="alert">
583 <span>@Translate("You do not have access to this page")</span>
584 </div>
585 }
586 }
587 else
588 {
589 <div class="alert alert-dark m-0" role="alert">
590 <span>@Translate("To work on this page, you must be signed in, in the frontend")</span>
591 </div>
592 }
593 }
594 }
595
596 </main>
597
598 <link rel="stylesheet" href="/Files/Templates/Designs/Swift/Assets/css/glightbox.min.css" />
599 <script src="/Files/Templates/Designs/Swift/Assets/js/glightbox.min.js"></script>
600 <script>
601 var lightbox = GLightbox({
602 touchNavigation: true,
603 loop: false,
604 autoplayVideos: true,
605 videosWidth: '80vw',
606 dragAutoSnap: true,
607 plyr: {
608 config: {
609 quality: 720,
610 muted: false,
611 volume: 100,
612 youtube: { noCookie: true, rel: 0, showinfo: 0, iv_load_policy: 3, modestbranding: 1 }
613 }
614 }
615 });
616 </script>
617 <script>
618 document.addEventListener('DOMContentLoaded', () => {
619 document.querySelectorAll('a').forEach(link => {
620 const href = link.getAttribute('href');
621 if (href && href.startsWith('https')) {
622 link.setAttribute('target', '_blank');
623 } else {
624 link.setAttribute('target', '_self');
625 }
626 });
627 });
628 </script>
629
630 @if (renderAsResponsive || !renderMobile)
631 {
632 <footer class="page-footer@(responsiveClassDesktop)" id="page-footer-desktop">
633 @if (footerDesktopLink != null)
634 {
635 @RenderGrid(footerDesktopLink.PageId)
636 }
637 </footer>
638 }
639
640 @if (renderAsResponsive || renderMobile)
641 {
642 <footer class="page-footer@(responsiveClassMobile)" id="page-footer-mobile">
643 @if (footerMobileLink != null)
644 {
645 @RenderGrid(footerMobileLink.PageId)
646 }
647 </footer>
648 }
649
650 @* Render any offcanvas menu here *@
651 @RenderSnippet("offcanvas")
652
653 @{
654 bool isErpConnectionDown = !Dynamicweb.Core.Converter.ToBoolean(Context.Current.Items["IsWebServiceConnectionAvailable"]);
655 string iconPath = "/Files/Templates/Designs/Swift/Assets/icons/";
656 }
657
658 @* Language selector modal *@
659 <div class="modal fade" id="PreferencesModal" tabindex="-1" aria-hidden="true">
660 <div class="modal-dialog modal-dialog-centered modal-sm" id="PreferencesModalContent">
661 @* The content here comes from an external request *@
662 </div>
663 </div>
664
665 @* Toast *@
666 <div aria-live="polite" aria-atomic="true">
667 <div class="toast-container position-fixed end-0 p-3" style="top:50px;z-index:1500;">
668 <div id="notificationToast" class="toast rounded-6 overflow-hidden" role="alert" aria-live="assertive" aria-atomic="true" data-bs-delay="1000">
669 <div class="toast-body d-flex align-items-end gap-3 theme theme-gray bg-dark text-light">
670 @ReadFile(iconPath + "check.svg")
671 <div id="notificationToast_Text" class=""></div>
672 </div>
673 </div>
674 </div>
675 </div>
676
677 @* Modal for dynamic content *@
678 <div class="modal fade js-product" id="DynamicModal" tabindex="-1" aria-hidden="true">
679 <div class="modal-dialog modal-dialog-centered modal-md">
680 <div class="modal-content theme light" id="DynamicModalContent">
681 @* The content here comes from an external request *@
682 </div>
683 </div>
684 </div>
685
686 @* Offcanvas for dynamic content *@
687 <div class="offcanvas offcanvas-end theme light" tabindex="-1" id="DynamicOffcanvas">
688 @* The content here comes from an external request *@
689 </div>
690
691 @if (Model.Area.Item.GetBoolean("ShowErpDownMessage") && !Dynamicweb.Core.Converter.ToBoolean(Context.Current.Items["IsWebServiceConnectionAvailable"]))
692 {
693 string erpDownMessageTheme = !string.IsNullOrWhiteSpace(Model.Area.Item.GetRawValueString("ErpDownMessageTheme")) ? " theme " + Model.Area.Item.GetRawValueString("ErpDownMessageTheme").Replace(" ", "").Trim().ToLower() : "theme light";
694
695 <div class="position-fixed bottom-0 end-0 p-3" style="z-index: 1040">
696 <div class="toast fade show border-0 @erpDownMessageTheme" role="alert" aria-live="assertive" aria-atomic="true">
697 <div class="toast-header">
698 <strong class="me-auto">@Translate("Connection down")</strong>
699 <button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
700 </div>
701 <div class="toast-body">
702 @Translate("We are experiencing some connectivity issues. Not all features may be available to you.")
703 </div>
704 </div>
705 </div>
706 }
707
708 @if (miniCartEnabled)
709 {
710 @* Open MiniCart when the cart is updated *@
711 <script type="module">
712 document.addEventListener('updated.swift.cart', (event) => {
713 let orderContext = event?.detail?.formData?.get("OrderContext");
714 updateCartSummary(orderContext);
715
716 @if (offcanvasMiniCartBehaviour == "2" || offcanvasMiniCartBehaviour == "3") {
717 <text>openMiniCartOffcanvas();</text>
718 }
719 });
720 </script>
721
722 if (offcanvasMiniCartBehaviour == "1" || offcanvasMiniCartBehaviour == "3")
723 {
724 @* Open MiniCart when toggle is clicked *@
725 <script type="module">
726 let miniCartToggles = document.querySelectorAll('.mini-cart-quantity');
727 miniCartToggles?.forEach((toggle) => {
728 toggle.parentElement.addEventListener('click', (event) => {
729 event.preventDefault();
730 let orderContext = toggle.dataset?.orderContext;
731 updateCartSummary(orderContext);
732
733 openMiniCartOffcanvas();
734 });
735 });
736 </script>
737 }
738
739 <script>
740
741 const updateCartSummary = (orderContext) => {
742 const dynamicOffcanvas = document.getElementById('DynamicOffcanvas');
743 swift.PageUpdater.UpdateFromUrlInline(event, '/Default.aspx?ID=@(cartSummaryPageId)&CartType=minicart&RequestPageID=@(Pageview.Page.ID)&OrderContext=' + orderContext +'', 'Swift_CartSummary.cshtml', dynamicOffcanvas);
744 };
745
746 const openMiniCartOffcanvas = () => {
747 const dynamicOffcanvas = document.getElementById('DynamicOffcanvas');
748 const miniCartOffcanvas = bootstrap.Offcanvas.getOrCreateInstance(dynamicOffcanvas);
749 dynamicOffcanvas.classList.add('overflow-y-auto');
750
751 if (!miniCartOffcanvas._isShown) {
752 miniCartOffcanvas.show();
753 hideActiveOffcanvases(miniCartOffcanvas);
754 }
755 };
756
757 const hideActiveOffcanvases = (miniCartOffcanvas) => {
758 let activeOffcanvases = document.querySelectorAll('.offcanvas.show');
759 activeOffcanvases?.forEach((offCanvas) => {
760 offCanvas = bootstrap.Offcanvas.getInstance(offCanvas);
761 if (offCanvas !== miniCartOffcanvas) {
762 offCanvas.hide();
763 }
764 });
765 };
766
767 </script>
768 }
769 @if (Pageview.Area.Name?.StartsWith("Xhelter") == false && Pageview.Area.Name?.StartsWith("Oase") == false)
770 {
771 <p class="d-none">@Pageview.Area.Name</p>
772 @RenderPartial("Components/Custom/CustomLanguageModal.cshtml")
773 }
774 </body>
775
776 </html>
777
778 }
779 else if (Pageview.IsVisualEditorMode)
780 {
781 <head>
782 <title>@Model.Title</title>
783 @* Bootstrap + Swift stylesheet *@
784 <link href="/Files/Templates/Designs/Swift/Assets/css/styles.css" rel="stylesheet" media="all" type="text/css">
785 </head>
786 <body class="p-3">
787 <div class="alert alert-danger" role="alert">
788 @Translate("Basic Swift setup is needed!")
789 </div>
790
791 @if (brandingPage == null)
792 {
793 <div class="alert alert-warning" role="alert">
794 @Translate("Please add a Branding page and reference it in website settings")
795 </div>
796 }
797
798 @if (themesParagraphs == null)
799 {
800 <div class="alert alert-warning" role="alert">
801 @Translate("Please add a Themes collection page and reference it in website settings")
802 </div>
803 }
804 </body>
805 }
806
807
808 @functions {
809 void SetMetaTags()
810 {
811 //Verification Tokens
812 string siteVerificationGoogle = Model.Area.Item.GetString("Google_Site_Verification") != null ? Model.Area.Item.GetString("Google_Site_Verification") : "";
813 string siteVerificationFacebook = Model.Area.Item.GetString("Facebook_Site_Verification") != null ? Model.Area.Item.GetString("Facebook_Site_Verification") : "";
814
815 //Generic Site Values
816 string openGraphFacebookAppID = Model.Area.Item.GetString("Fb_app_id") != null ? Model.Area.Item.GetString("Fb_app_id") : "";
817 string openGraphType = Model.Area.Item.GetString("Open_Graph_Type") != null ? Model.Area.Item.GetString("Open_Graph_Type") : "";
818 string openGraphSiteName = Model.Area.Item.GetString("Open_Graph_Site_Name") != null ? Model.Area.Item.GetString("Open_Graph_Site_Name") : "";
819
820 string twitterCardSite = Model.Area.Item.GetString("Twitter_Site") != null ? Model.Area.Item.GetString("Twitter_Site") : "";
821
822 //Page specific values
823 string openGraphSiteTitle = Model.Area.Item.GetString("Open_Graph_Title") != null ? Model.Area.Item.GetString("Open_Graph_Title") : "";
824 FileViewModel openGraphImage = Model.Area.Item.GetFile("Open_Graph_Image");
825 string openGraphImageALT = Model.Area.Item.GetString("Open_Graph_Image_ALT") != null ? Model.Area.Item.GetString("Open_Graph_Image_ALT") : "";
826 string openGraphDescription = Model.Area.Item.GetString("Open_Graph_Description") != null ? Model.Area.Item.GetString("Open_Graph_Description") : "";
827
828 string twitterCardURL = Model.Area.Item.GetString("Twitter_URL") != null ? Model.Area.Item.GetString("Twitter_URL") : "";
829 string twitterCardTitle = Model.Area.Item.GetString("Twitter_Title") != null ? Model.Area.Item.GetString("Twitter_Title") : "";
830 string twitterCardDescription = Model.Area.Item.GetString("Twitter_Description") != null ? Model.Area.Item.GetString("Twitter_Description") : "";
831 FileViewModel twitterCardImage = Model.Area.Item.GetFile("Twitter_Image");
832 string twitterCardImageALT = Model.Area.Item.GetString("Twitter_Image_ALT") != null ? Model.Area.Item.GetString("Twitter_Image_ALT") : "";
833 string topImage = Pageview.Page.TopImage.StartsWith("/Files", StringComparison.OrdinalIgnoreCase) ? Pageview.Page.TopImage : $"/Files{Pageview.Page.TopImage}";
834
835 if (string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString["ProductID"]))
836 {
837 if (!string.IsNullOrEmpty(Model.Description))
838 {
839 Pageview.Meta.AddTag($"<meta property=\"og:description\" content=\"{Model.Description}\">");
840 }
841 else
842 {
843 Pageview.Meta.AddTag($"<meta property=\"og:description\" content=\"{openGraphDescription}\">");
844 }
845
846 if (!string.IsNullOrEmpty(Pageview.Page.TopImage))
847 {
848 Pageview.Meta.AddTag($"<meta property=\"og:image\" content=\"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}{topImage}\">");
849 Pageview.Meta.AddTag($"<meta property=\"og:image:secure_url\" content=\"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}{topImage}\">");
850 }
851 else if (openGraphImage != null)
852 {
853 Pageview.Meta.AddTag($"<meta property=\"og:image\" content=\"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}{openGraphImage.Path}\">");
854 Pageview.Meta.AddTag($"<meta property=\"og:image:secure_url\" content=\"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}{openGraphImage.Path}\">");
855 }
856
857 if (!string.IsNullOrEmpty(openGraphImageALT))
858 {
859 Pageview.Meta.AddTag($"<meta property=\"og:image:alt\" content=\"{openGraphImageALT}\">");
860 }
861 if (!string.IsNullOrEmpty(twitterCardDescription))
862 {
863 Pageview.Meta.AddTag("twitter:description", twitterCardDescription);
864 }
865
866 if (!string.IsNullOrEmpty(Pageview.Page.TopImage))
867 {
868 Pageview.Meta.AddTag("twitter:image", $"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}{topImage}");
869 }
870 else if (twitterCardImage != null)
871 {
872 Pageview.Meta.AddTag("twitter:image", $"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}{openGraphImage.Path}");
873 }
874
875 if (!string.IsNullOrEmpty(twitterCardImageALT))
876 {
877 Pageview.Meta.AddTag("twitter:image:alt", twitterCardImageALT);
878 }
879 }
880
881 if (!string.IsNullOrEmpty(siteVerificationGoogle))
882 {
883 Pageview.Meta.AddTag("google-site-verification", siteVerificationGoogle);
884 }
885
886 if (!string.IsNullOrEmpty(siteVerificationFacebook))
887 {
888 Pageview.Meta.AddTag("facebook-domain-verification", siteVerificationFacebook);
889 }
890
891 if (!string.IsNullOrEmpty(openGraphFacebookAppID))
892 {
893 Pageview.Meta.AddTag($"<meta property=\"fb:app_id\" content=\"{openGraphFacebookAppID}\">");
894 }
895
896 if (!string.IsNullOrEmpty(openGraphType))
897 {
898 Pageview.Meta.AddTag($"<meta property=\"og:type\" content=\"{openGraphType}\">");
899 }
900
901 if (!string.IsNullOrEmpty(openGraphSiteName))
902 {
903 Pageview.Meta.AddTag($"<meta property=\"og:url\" content=\"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}{Pageview.SearchFriendlyUrl}\">");
904 }
905
906 if (!string.IsNullOrEmpty(openGraphSiteName))
907 {
908 Pageview.Meta.AddTag($"<meta property=\"og:site_name\" content=\"{openGraphSiteName}\">");
909 }
910
911 if (!string.IsNullOrEmpty(Model.Title))
912 {
913 Pageview.Meta.AddTag($"<meta property=\"og:title\" content=\"{Model.Title}\">");
914 }
915 else
916 {
917 Pageview.Meta.AddTag($"<meta property=\"og:title\" content=\"{openGraphSiteTitle}\">");
918 }
919
920 if (!string.IsNullOrEmpty(twitterCardSite))
921 {
922 Pageview.Meta.AddTag("twitter:site", twitterCardSite);
923 }
924
925 if (!string.IsNullOrEmpty(twitterCardURL))
926 {
927 Pageview.Meta.AddTag("twitter:url", twitterCardURL);
928 }
929
930 if (!string.IsNullOrEmpty(twitterCardTitle))
931 {
932 Pageview.Meta.AddTag("twitter:title", twitterCardTitle);
933 }
934 }
935 }
936