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_27341607be644aca8758dedade79b103.Execute() in D:\dynamicweb.net\Solutions\Degree\proff1.cloud.dynamicweb-cms.com\files\Templates\Designs\Swift\_parsed\Swift_Page.parsed.cshtml:line 393
at RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context, TextWriter reader)
at RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass16_0.<RunCompile>b__0(TextWriter writer)
at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
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 @using Dynamicweb.Ecommerce.ProductCatalog
7
8 @{
9 string swiftVersion = ReadFile("/Files/Templates/Designs/Swift/swift_version.txt");
10 bool renderAsResponsive = Model.Area.Item.GetString("DeviceRendering", "responsive").Equals("responsive", StringComparison.OrdinalIgnoreCase);
11 bool renderMobile = Pageview.Device == Dynamicweb.Frontend.Devices.DeviceType.Mobile || Pageview.Device == Dynamicweb.Frontend.Devices.DeviceType.Tablet;
12 string responsiveClassDesktop = string.Empty;
13 string responsiveClassMobile = string.Empty;
14 if (renderAsResponsive)
15 {
16 responsiveClassDesktop = " d-none d-xl-block";
17 responsiveClassMobile = " d-block d-xl-none";
18 }
19
20 var disableWideBreakpoints = Model.Area?.Item?.GetRawValueString("DisableWideBreakpoints", "default");
21
22 var brandingPageId = Model.Area.Item.GetLink("BrandingPage") != null ? Model.Area.Item.GetLink("BrandingPage").PageId : 0;
23 var themePageId = Model.Area.Item.GetLink("ThemesPage") != null ? Model.Area.Item.GetLink("ThemesPage").PageId : 0;
24 string customHeaderInclude = Model.Area.Item.GetFile("CustomHeaderInclude") != null ? Model.Area.Item.GetFile("CustomHeaderInclude").Name : string.Empty;
25
26 var brandingPage = Dynamicweb.Content.Services.Pages?.GetPage(brandingPageId) ?? null;
27 var themesParagraphLastChanged = Dynamicweb.Content.Services.Paragraphs.GetParagraphsByPageId(themePageId).OrderByDescending(p => p.Audit.LastModifiedAt).FirstOrDefault();
28
29 var cssLastModified = brandingPage.Audit.LastModifiedAt > themesParagraphLastChanged.Audit.LastModifiedAt ? brandingPage.Audit.LastModifiedAt : themesParagraphLastChanged.Audit.LastModifiedAt;
30 var cssThemeAndBrandingStyleFileInfo = new System.IO.FileInfo(Dynamicweb.Core.SystemInformation.MapPath($"/Files/Templates/Designs/Swift/_parsed/Swift_css/Swift_styles_{Model.Area.ID}.min.css"));
31
32 // Schema.org details for PDP
33 string productId = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString.Get("ProductID")) ? Dynamicweb.Context.Current.Request.QueryString.Get("ProductID") : "";
34 bool isProductDetailsPage = !string.IsNullOrEmpty(productId);
35 bool isArticlePage = Model.ItemType == "Swift_Article";
36 string schemaOrgType = string.Empty;
37
38 if (isProductDetailsPage)
39 {
40 schemaOrgType = "itemscope=\"\" itemtype=\"https://schema.org/Product\"";
41 }
42
43 if (isArticlePage)
44 {
45 schemaOrgType = "itemscope=\"\" itemtype=\"https://schema.org/Article\"";
46 }
47
48 if (!cssThemeAndBrandingStyleFileInfo.Exists || cssThemeAndBrandingStyleFileInfo.LastWriteTime < brandingPage.Audit.LastModifiedAt)
49 {
50 //Branding page has been saved or the file is missing. Rewrite the file to disc.
51 if (brandingPageId > 0)
52 {
53 var brandingPageview = Dynamicweb.Frontend.PageView.GetPageviewByPageID(brandingPageId);
54 brandingPageview.Redirect = false;
55 brandingPageview.Output();
56 }
57 }
58
59 if (!cssThemeAndBrandingStyleFileInfo.Exists || cssThemeAndBrandingStyleFileInfo.LastWriteTime < themesParagraphLastChanged.Audit.LastModifiedAt)
60 {
61 //Branding page has been saved or the file is missing. Rewrite the file to disc.
62 if (themePageId > 0)
63 {
64 var themePageview = Dynamicweb.Frontend.PageView.GetPageviewByPageID(themePageId);
65 themePageview.Redirect = false;
66 themePageview.Output();
67 }
68 }
69
70 var cssStyleFileInfo = new System.IO.FileInfo(Dynamicweb.Core.SystemInformation.MapPath("/Files/Templates/Designs/Swift/Assets/css/styles.css"));
71 var jsFileInfo = new System.IO.FileInfo(Dynamicweb.Core.SystemInformation.MapPath("/Files/Templates/Designs/Swift/Assets/dist/app.bundle.js"));
72
73 string masterTheme = !string.IsNullOrWhiteSpace(Model.Area.Item.GetRawValueString("Theme")) ? " theme " + Model.Area.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : "";
74
75 string favicon = Model.Area.Item.GetFile("Favicon") != null ? Model.Area.Item.GetFile("Favicon").Path : "/Files/Templates/Designs/Swift/Assets/Images/favicon.png";
76
77 string headerCssClass = "sticky-top";
78 bool movePageBehind = false;
79
80 if (Pageview.Page.PropertyItem != null)
81 {
82 headerCssClass = Pageview.Page.PropertyItem["MoveThisPageBehindTheHeader"] != null ? Pageview.Page.PropertyItem["MoveThisPageBehindTheHeader"].ToString() : "sticky-top";
83 movePageBehind = headerCssClass == "fixed-top" && !Pageview.IsVisualEditorMode ? true : false;
84 }
85
86 headerCssClass = headerCssClass == "" ? "sticky-top" : headerCssClass;
87 headerCssClass = Pageview.IsVisualEditorMode ? "" : headerCssClass;
88
89 string googleTagManagerID = Model.Area.Item.GetString("GoogleTagManagerID");
90 string googleAnalyticsMeasurementID = Model.Area.Item.GetString("GoogleAnalyticsMeasurementID");
91 var cookieOptInLevel = CookieManager.GetCookieOptInLevel();
92 bool allowTracking = cookieOptInLevel == CookieOptInLevel.All || (cookieOptInLevel == CookieOptInLevel.Functional && CookieManager.GetCookieOptInCategories().Contains("Statistical"));
93
94 Dynamicweb.Context.Current.Response.AddHeader("link", $"</Files/Templates/Designs/Swift/Assets/css/styles.css?{cssStyleFileInfo.LastWriteTime.Ticks}>; rel=preload; as=style;");
95 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;");
96 Dynamicweb.Context.Current.Response.AddHeader("link", $"</Files/Templates/Designs/Swift/Assets/js/aos.js?{jsFileInfo.LastWriteTime.Ticks}; rel=preload; as=script;");
97 Dynamicweb.Context.Current.Response.AddHeader("link", $"</Files/Templates/Designs/Swift/Assets/dist/app.bundle.js?{jsFileInfo.LastWriteTime.Ticks}; rel=preload; as=script;");
98 //Dynamicweb.Context.Current.Response.Flush(); //This sends the headers where we are now in the rendering making the TTFB faster
99
100 SetMetaTags();
101
102 List<Dynamicweb.Content.Page> languages = new List<Dynamicweb.Content.Page>();
103
104 if (Pageview.Area.IsMaster)
105 {
106 languages.Add(Pageview.Page);
107 if (Pageview.Page.Languages != null)
108 {
109 foreach (var language in Pageview.Page.Languages)
110 {
111 languages.Add(language);
112 }
113 }
114 }
115 else
116 {
117 languages.Add(Pageview.Page.MasterPage);
118 if (Pageview.Page.MasterPage != null)
119 {
120 if (Pageview.Page.MasterPage.Languages != null)
121 {
122 foreach (var language in Pageview.Page.MasterPage.Languages)
123 {
124 languages.Add(language);
125 }
126 }
127 }
128 }
129
130 string siteLanguage = Pageview.Area.CultureInfo.Name;
131 Uri url = Dynamicweb.Context.Current.Request.Url;
132 string hostName = url.Host; // domain.com/da-dk or domain.com/en-us
133
134 var ecomCountries = Dynamicweb.Ecommerce.Services.Countries.GetCountries();
135 var ecomCurrencies = Dynamicweb.Ecommerce.Services.Currencies.GetAllCurrencies();
136 }
137 <!doctype html>
138 <html lang="@Pageview.Area.CultureInfo.TwoLetterISOLanguageName">
139 <head>
140 <!-- @swiftVersion -->
141 @* Required meta tags *@
142 <meta charset="utf-8">
143 <meta name="viewport" content="height=device-height, width=device-width, initial-scale=1.0">
144 <!--$$Snippet(meta)-->
145
146 <link rel="shortcut icon" href="@favicon">
147 <link rel="apple-touch-icon" href="/Files/Templates/Designs/Swift/Assets/Images/logo_transparent.png">
148
149 @Model.MetaTags
150
151 @{
152 var productService = new Dynamicweb.Ecommerce.Products.ProductService();
153 //var regularProduct = productService.GetProductById(productId, "", true);
154 var productBrand = "";
155 //regularProduct?.ProductFieldValues.GetProductFieldValue("TK_Brand").Value;
156 //var productGroup = regularProduct?.GroupPaths;
157
158 var alreadyWrittenTwoletterIsos = new List<string>();
159 @* Languages meta data *@
160 foreach (var language in languages)
161 {
162 hostName = url.Host;
163 if (language?.Area != null)
164 {
165 if (language.Area?.MasterArea != null && !string.IsNullOrEmpty(language.Area.MasterArea.DomainLock))
166 {
167 hostName = language.Area.MasterArea.DomainLock; //dk.domain.com or dk-domain.dk
168 }
169 if (language != null && language.Published && language.Area.Active && language.Area.Published)
170 {
171 if (!string.IsNullOrEmpty(language.Area.DomainLock))
172 {
173 hostName = language.Area.DomainLock; //dk.domain.com or dk-domain.dk
174 }
175 string querystring = $"Default.aspx?ID={language.ID}";
176 if (!string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString["GroupID"]))
177 {
178 querystring += $"&GroupID={Dynamicweb.Context.Current.Request.QueryString["GroupID"]}";
179 }
180 if (!string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString["ProductID"]))
181 {
182 querystring += $"&ProductID={Dynamicweb.Context.Current.Request.QueryString["ProductID"]}";
183 }
184 if (!string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString["VariantID"]))
185 {
186 querystring += $"&VariantID={Dynamicweb.Context.Current.Request.QueryString["VariantID"]}";
187 }
188
189 string friendlyUrl = Dynamicweb.Frontend.SearchEngineFriendlyURLs.GetFriendlyUrl(querystring);
190 if (language.Area.RedirectFirstPage && language.ParentPageId == 0 && language.Sort == 1)
191 {
192 friendlyUrl = "/";
193 }
194 string href = $"{url.Scheme}://{hostName}{friendlyUrl}";
195
196
197 <link rel="alternate" hreflang="@language.Area.CultureInfo.Name.ToLower()" href="@href">
198 if (!alreadyWrittenTwoletterIsos.Contains(language.Area.CultureInfo.TwoLetterISOLanguageName))
199 {
200 <link rel="alternate" hreflang="@language.Area.CultureInfo.TwoLetterISOLanguageName.ToLower()" href="@href">
201 }
202 }
203 }
204 }
205 }
206
207 @if (!isProductDetailsPage)
208 {
209 <title>@Model.Title</title>
210 }
211 @* Bootstrap + Swift stylesheet *@
212 <link href="/Files/Templates/Designs/Swift/Assets/css/styles.css?@cssStyleFileInfo.LastWriteTime.Ticks" rel="stylesheet" media="all" type="text/css">
213
214 @if (disableWideBreakpoints != "disableBoth")
215 {
216 <style>
217 @@media ( min-width: 1600px ) {
218 .container-xxl,
219 .container-xl,
220 .container-lg,
221 .container-md,
222 .container-sm,
223 .container {
224 max-width: 1520px;
225 }
226 }
227 </style>
228
229
230
231 if (disableWideBreakpoints != "disableUltraWideOnly")
232 {
233 <style>
234 @@media ( min-width: 1920px ) {
235 .container-xxl,
236 .container-xl,
237 .container-lg,
238 .container-md,
239 .container-sm,
240 .container {
241 max-width: 1820px;
242 }
243 }
244 </style>
245 }
246 }
247
248 @* Branding and Themes min stylesheet *@
249 <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">
250 <script src="/Files/Templates/Designs/Swift/Assets/js/aos.js?@jsFileInfo.LastWriteTime.Ticks" defer></script>
251 <script src="/Files/Templates/Designs/Swift/Assets/dist/app.bundle.js?@jsFileInfo.LastWriteTime.Ticks" defer></script>
252 <script src="/Files/Templates/Designs/Swift/Assets/js/COMM_custom.js?@jsFileInfo.LastWriteTime.Ticks" defer></script>
253
254 <script type="module">
255 AOS.init({ duration: 400, delay: 100, easing: 'ease-in-out', mirror: false, disable: window.matchMedia('(prefers-reduced-motion: reduce)') });
256 swift.Scroll.hideHeadersOnScroll();
257 swift.Scroll.handleAlternativeTheme();
258 </script>
259
260 @* Google tag manager *@
261 @if (!string.IsNullOrWhiteSpace(googleTagManagerID) && allowTracking)
262 {
263 <script>
264 (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
265 new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
266 j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
267 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
268 })(window, document, 'script', 'dataLayer', '@(googleTagManagerID)');
269
270 function gtag() { dataLayer.push(arguments); }
271 </script>
272 }
273
274 @if (!string.IsNullOrWhiteSpace(googleAnalyticsMeasurementID) && allowTracking)
275 {
276 var GoogleAnalyticsDebugMode = "";
277 bool isLoggedInBackendUser = false;
278
279 if (Dynamicweb.Security.UserManagement.User.GetCurrentBackendUser() != null)
280 {
281 isLoggedInBackendUser = true;
282 }
283
284 if (Model.Area.Item.GetBoolean("EnableGoogleAnalyticsDebugMode") && isLoggedInBackendUser)
285 {
286 GoogleAnalyticsDebugMode = ", {'debug_mode': true}";
287 }
288
289 <script async src="https://www.googletagmanager.com/gtag/js?id=@googleAnalyticsMeasurementID"></script>
290 <script>
291 window.dataLayer = window.dataLayer || [];
292 function gtag() { dataLayer.push(arguments); }
293 gtag('js', new Date());
294 gtag('config', '@googleAnalyticsMeasurementID'@GoogleAnalyticsDebugMode);
295 </script>
296 }
297
298 @if (!string.IsNullOrWhiteSpace(customHeaderInclude))
299 {
300 @RenderPartial($"Components/Custom/{customHeaderInclude}")
301 }
302 </head>
303 <body class="brand @(masterTheme)" id="page@(Model.ID)">
304
305 @* Google tag manager *@
306 @if (!string.IsNullOrWhiteSpace(googleTagManagerID) && allowTracking)
307 {
308 <noscript>
309 <iframe src="https://www.googletagmanager.com/ns.html?id=@(googleTagManagerID)"
310 height="0" width="0" style="display:none;visibility:hidden"></iframe>
311 </noscript>
312 }
313
314 @if (renderAsResponsive || !renderMobile)
315 {
316 <header class="page-header @headerCssClass top-0@(responsiveClassDesktop)" id="page-header-desktop">
317 @if (@Model.Area.Item.GetLink("HeaderDesktop") != null)
318 {
319 @RenderGrid(@Model.Area.Item.GetLink("HeaderDesktop").PageId)
320 }
321 </header>
322 }
323
324 @if ((renderAsResponsive || renderMobile))
325 {
326 <header class="page-header @headerCssClass top-0@(responsiveClassMobile)" id="page-header-mobile">
327 @if (@Model.Area.Item.GetLink("HeaderMobile") != null)
328 {
329 @RenderGrid(@Model.Area.Item.GetLink("HeaderMobile").PageId)
330 }
331 </header>
332 }
333
334 <main id="content" @(schemaOrgType)>
335 <div data-intersect></div>
336 @inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.PageViewModel>
337 @using System
338 @using System.Web
339 @using System.Web.Helpers
340 @using Dynamicweb.Ecommerce.ProductCatalog
341 @using System.Globalization;
342
343
344 @{
345 string productIdFromUrl = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString.Get("ProductID")) ? Dynamicweb.Context.Current.Request.QueryString.Get("ProductID") : string.Empty;
346 bool isProductDetail = !string.IsNullOrEmpty(productIdFromUrl) && Pageview.Page.NavigationTag.ToLower() == "shop";
347
348 bool isArticlePagePage = Model.ItemType == "Swift_Article";
349 bool isArticleListPage = Model.ItemType == "Swift_ArticleListPage";
350 string schemaOrgProp = string.Empty;
351 if(isArticlePagePage)
352 {
353 schemaOrgProp = "itemprop=\"articleBody\"";
354 }
355
356 string theme = "";
357 string gridContent = "";
358
359 if (Model.PropertyItem != null)
360 {
361 theme = !string.IsNullOrWhiteSpace(Model.PropertyItem.GetRawValueString("Theme")) ? "theme " + Model.PropertyItem.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : "";
362 }
363
364 if (Model.Item != null || Pageview.IsVisualEditorMode)
365 {
366 if (!isProductDetail)
367 {
368 gridContent = Model.Grid("Grid", "Grid", "default:true;sort:1", "Page");
369 }
370 else
371 {
372 var productObject = Dynamicweb.Ecommerce.Services.Products.GetProductById(productIdFromUrl, "", Pageview.Area.EcomLanguageId);
373 var detailPage = Dynamicweb.Ecommerce.Services.ProductGroups.GetGroup(productObject.PrimaryGroupId)?.Meta.PrimaryPage ?? string.Empty;
374 var detailPageId = detailPage != string.Empty ? Convert.ToInt16(detailPage.Substring(detailPage.LastIndexOf('=') + 1)) : GetPageIdByNavigationTag("ProductDetailPage");
375
376 @RenderGrid(detailPageId)
377 }
378 }
379
380 bool doNotRenderPage = false;
381
382 //Check if we are on the poduct detail page, and if there is data to render
383 ProductViewModel product = new ProductViewModel();
384 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails"))
385 {
386 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"];
387 if (string.IsNullOrEmpty(product.Id)) {
388 doNotRenderPage = true;
389 }
390
391 // Lookup brand name if it exists
392 var pBrandName = "Ukjent merke"; // Fallback hvis merke mangler
393 if (product.ProductFields.ContainsKey("TK_Brand") && product.ProductFields["TK_Brand"]?.Value != null)
394 {
395 pBrandName = product.ProductFields["TK_Brand"].Value.ToString();
396 }
397
398 // Lookup MPN
399 var pMpn = "";
400 if (product.ProductFields.ContainsKey("P1_Product_Manufacturer_Product_Number") && product.ProductFields["P1_Product_Manufacturer_Product_Number"]?.Value != null)
401 {
402 pMpn = product.ProductFields["P1_Product_Manufacturer_Product_Number"].Value.ToString();
403 }
404
405 // Clean description
406 var rawDescription = product.ShortDescription ?? product.LongDescription ?? "";
407 var noHtml = System.Text.RegularExpressions.Regex.Replace(rawDescription, "<.*?>", " ");
408 var pShortDescription = System.Web.HttpUtility.HtmlDecode(noHtml).Trim();
409 pShortDescription = System.Text.RegularExpressions.Regex.Replace(pShortDescription, @"\s+", " ");
410
411 // Image url
412 string imagePath = product?.DefaultImage?.Value ?? "";
413 var request = HttpContext.Current.Request;
414 var baseUrl = request.Url.Scheme + "://" + request.Url.Authority;
415
416 string absoluteImageUrl = "";
417 if (!string.IsNullOrEmpty(imagePath))
418 {
419 absoluteImageUrl = baseUrl + imagePath.Replace(" ", "%20");
420 }
421
422 var currentUrl = request.Url.AbsoluteUri;
423
424 // Price
425 var priceWithVat = product.Price.PriceWithVat;
426 string formattedPriceWithVat = priceWithVat.ToString("0.00", CultureInfo.InvariantCulture);
427
428 // In stock or not
429 string availability = product.StockLevel > 0 ? "https://schema.org/InStock" : "https://schema.org/OutOfStock";
430
431
432 <script type="application/ld+json">
433 {
434 "@@context": "https://schema.org/",
435 "@@type": "Product",
436 "name": @Json.Encode(product.Name),
437 "image": [@Json.Encode(absoluteImageUrl)],
438 "description": @Json.Encode(pShortDescription),
439 "sku": @Json.Encode(product.Number),
440 "mpn": @Json.Encode(pMpn),
441 "gtin13": @Json.Encode(product.EAN),
442 "brand": {
443 "@@type": "Brand",
444 "name": @Json.Encode(pBrandName)
445 },
446 "offers": {
447 "@@type": "Offer",
448 "url": @Json.Encode(currentUrl),
449 "priceCurrency": "NOK",
450 "price": @formattedPriceWithVat,
451 "itemCondition": "https://schema.org/NewCondition",
452 "availability": @Json.Encode(availability),
453 "seller": {
454 "@@type": "Organization",
455 "name": "Proff1.no"
456 }
457 }
458 }
459 </script>
460
461 }
462
463 //Render the page
464 if (!doNotRenderPage) {
465 string itemIdentifier = Model?.Item?.SystemName != null ? "item_" + Model.Item.SystemName.ToLower() : "item_Swift_Page";
466
467
468 <div class="@theme @itemIdentifier" @schemaOrgProp>
469 @if (isArticleListPage)
470 {
471 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\"";
472
473 <form @hx id="ArticleFacetForm">
474 @gridContent
475 </form>
476 <script type="module" src="/Files/Templates/Designs/Swift/Assets/js/htmx.js"></script>
477 <script type="module">
478 document.addEventListener('htmx:confirm', (event) => {
479 let filters = event.detail.elt.querySelectorAll('select');
480 for (var i = 0; i < filters.length; i++) {
481 let input = filters[i];
482 if (input.name && !input.value) {
483 input.name = '';
484 }
485 }
486 });
487
488 document.addEventListener('htmx:beforeOnLoad', (event) => {
489 swift.Scroll.stopIntersectionObserver();
490 });
491
492 document.addEventListener('htmx:afterOnLoad', () => {
493 swift.Scroll.hideHeadersOnScroll();
494 swift.Scroll.handleAlternativeTheme();
495 });
496 </script>
497 }
498 else
499 {
500 @gridContent
501 }
502 </div>
503
504 } else {
505 <div class="container">
506 <div class="alert alert-info" role="alert">@Translate("Sorry. There is nothing to view here")</div>
507 </div>
508 }
509
510 if (!Model.IsCurrentUserAllowed)
511 {
512 int signInPage = GetPageIdByNavigationTag("SignInPage");
513 int dashboardPage = GetPageIdByNavigationTag("MyAccountDashboardPage");
514
515 if (!Pageview.IsVisualEditorMode)
516 {
517 if (signInPage != 0)
518 {
519 if (signInPage != Model.ID) {
520 Dynamicweb.Context.Current.Response.Redirect("/Default.aspx?ID=" + signInPage);
521 } else {
522 if (dashboardPage != 0) {
523 Dynamicweb.Context.Current.Response.Redirect("/Default.aspx?ID=" + dashboardPage);
524 } else {
525 Dynamicweb.Context.Current.Response.Redirect("/");
526 }
527 }
528 }
529 else
530 {
531 <div class="alert alert-dark m-0" role="alert">
532 <span>@Translate("You do not have access to this page")</span>
533 </div>
534 }
535 }
536 else
537 {
538 <div class="alert alert-dark m-0" role="alert">
539 <span>@Translate("To work on this page, you must be signed in, in the frontend")</span>
540 </div>
541 }
542 }
543 }
544
545 </main>
546
547 @if (renderAsResponsive || !renderMobile)
548 {
549 <footer class="page-footer@(responsiveClassDesktop)" id="page-footer-desktop">
550 @if (@Model.Area.Item.GetLink("FooterDesktop") != null)
551 {
552 @RenderGrid(@Model.Area.Item.GetLink("FooterDesktop").PageId)
553 }
554 </footer>
555 }
556
557 @if (renderAsResponsive || renderMobile)
558 {
559 <footer class="page-footer@(responsiveClassMobile)" id="page-footer-mobile">
560 @if (@Model.Area.Item.GetLink("FooterMobile") != null)
561 {
562 @RenderGrid(@Model.Area.Item.GetLink("FooterMobile").PageId)
563 }
564 </footer>
565 }
566
567 @* Render any offcanvas menu here *@
568 @RenderSnippet("offcanvas")
569
570 @{
571 bool isErpConnectionDown = !Dynamicweb.Core.Converter.ToBoolean(Context.Current.Items["IsWebServiceConnectionAvailable"]);
572 }
573
574 @* Language selector modal *@
575 @if (languages.Count > 1 || ecomCountries.Count > 1 || ecomCurrencies.Count() > 1)
576 {
577 <div class="modal fade" id="PreferencesModal" tabindex="-1" aria-hidden="true">
578 <div class="modal-dialog modal-dialog-centered modal-sm" id="PreferencesModalContent">
579 @* The content here comes from an external request *@
580 </div>
581 </div>
582 }
583
584 @* Favorite toast *@
585 <div aria-live="polite" aria-atomic="true">
586 <div class="position-fixed bottom-0 end-0 p-3" style="z-index: 11">
587 <div id="favoriteNotificationToast" class="toast" role="alert" aria-live="assertive" aria-atomic="true">
588 <div class="toast-header">
589 <strong class="me-auto">@Translate("Favorite list updated")</strong>
590 <button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
591 </div>
592 <div class="toast-body d-flex gap-3">
593 <div id="favoriteNotificationToast_Image"></div>
594 <div id="favoriteNotificationToast_Text"></div>
595 </div>
596 </div>
597 </div>
598 </div>
599
600 @* Modal for dynamic content *@
601 <div class="modal fade js-product" id="DynamicModal" tabindex="-1" aria-hidden="true">
602 <div class="modal-dialog modal-dialog-centered modal-md">
603 <div class="modal-content theme light" id="DynamicModalContent">
604 @* The content here comes from an external request *@
605 </div>
606 </div>
607 </div>
608
609 @* Offcanvas for dynamic content *@
610 <div class="offcanvas offcanvas-end theme light" tabindex="-1" id="DynamicOffcanvas" style="width: 30rem">
611 @* The content here comes from an external request *@
612 </div>
613
614 @if (isErpConnectionDown && Model.Area.Item.GetBoolean("ShowErpDownMessage"))
615 {
616 string erpDownMessageTheme = !string.IsNullOrWhiteSpace(Model.Area.Item.GetRawValueString("ErpDownMessageTheme")) ? " theme " + Model.Area.Item.GetRawValueString("ErpDownMessageTheme").Replace(" ", "").Trim().ToLower() : "theme light";
617
618 <div class="position-fixed bottom-0 end-0 p-3" style="z-index: 1040">
619 <div class="toast fade show border-0 @erpDownMessageTheme" role="alert" aria-live="assertive" aria-atomic="true">
620 <div class="toast-header">
621 <strong class="me-auto">@Translate("Connection down")</strong>
622 <button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
623 </div>
624 <div class="toast-body">
625 @Translate("We are experiencing some connectivity issues. Not all features may be available to you.")
626 </div>
627 </div>
628 </div>
629 }
630 </body>
631 </html>
632
633 @functions {
634 void SetMetaTags()
635 {
636 //Verification Tokens
637 string siteVerificationGoogle = Model.Area.Item.GetString("Google_Site_Verification") != null ? Model.Area.Item.GetString("Google_Site_Verification") : "";
638 //string siteVerificationYandex = Model.Area.Item.GetString("Yandex_Verification") != null ? Model.Area.Item.GetString("Yandex_Verification") : "";
639 //string siteVerificationMS = Model.Area.Item.GetString("Msvalidate_01") != null ? Model.Area.Item.GetString("Msvalidate_01") : "";
640 //string siteVerificationAlexa = Model.Area.Item.GetString("AlexaVerifyID") != null ? Model.Area.Item.GetString("AlexaVerifyID") : "";
641 //string siteVerificationPinterest = Model.Area.Item.GetString("P_domain_verify") != null ? Model.Area.Item.GetString("P_domain_verify") : "";
642 //string siteVerificationNorton = Model.Area.Item.GetString("Norton_safeweb_site_verification") != null ? Model.Area.Item.GetString("Norton_safeweb_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 productId = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString.Get("ProductID")) ? Dynamicweb.Context.Current.Request.QueryString.Get("ProductID") : "";
663 bool isProductDetailsPage = !string.IsNullOrEmpty(productId);
664
665 if (string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString["ProductID"]))
666 {
667 if (!string.IsNullOrEmpty(Model.Description))
668 {
669 Pageview.Meta.AddTag($"<meta property=\"og:description\" content=\"{Model.Description}\" />");
670 }
671 else
672 {
673 Pageview.Meta.AddTag($"<meta property=\"og:description\" content=\"{openGraphDescription}\" />");
674 }
675
676 if (!string.IsNullOrEmpty(Pageview.Page.TopImage))
677 {
678 Pageview.Meta.AddTag($"<meta property=\"og:image\" content=\"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}/Files{Pageview.Page.TopImage}\" />");
679 Pageview.Meta.AddTag($"<meta property=\"og:image:secure_url\" content=\"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}/Files{Pageview.Page.TopImage}\" />");
680 }
681 else if (openGraphImage != null)
682 {
683 Pageview.Meta.AddTag($"<meta property=\"og:image\" content=\"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}{openGraphImage.Path}\" />");
684 Pageview.Meta.AddTag($"<meta property=\"og:image:secure_url\" content=\"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}{openGraphImage.Path}\" />");
685 }
686
687 if (!string.IsNullOrEmpty(openGraphImageALT))
688 {
689 Pageview.Meta.AddTag($"<meta property=\"og:image:alt\" content=\"{openGraphImageALT}\"");
690 }
691 if (!string.IsNullOrEmpty(twitterCardDescription))
692 {
693 Pageview.Meta.AddTag("twitter:description", twitterCardDescription);
694 }
695
696 if (!string.IsNullOrEmpty(Pageview.Page.TopImage))
697 {
698 Pageview.Meta.AddTag("twitter:image", $"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}/Files{Pageview.Page.TopImage}");
699 }
700 else if (twitterCardImage != null)
701 {
702 Pageview.Meta.AddTag("twitter:image", $"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}{openGraphImage.Path}");
703 }
704
705 if (!string.IsNullOrEmpty(twitterCardImageALT))
706 {
707 Pageview.Meta.AddTag("twitter:image:alt", twitterCardImageALT);
708 }
709 }
710
711
712 if (!string.IsNullOrEmpty(Model.Description))
713 {
714 if (!isProductDetailsPage)
715 {
716 Pageview.Meta.AddTag($"<meta name=\"description\" content=\"{Model.Description}\" />");
717 }
718 }
719
720 if (!string.IsNullOrEmpty(siteVerificationGoogle))
721 {
722 Pageview.Meta.AddTag("google-site-verification", siteVerificationGoogle);
723 }
724
725 if (!string.IsNullOrEmpty(openGraphFacebookAppID))
726 {
727 Pageview.Meta.AddTag($"<meta property=\"fb:app_id\" content=\"{openGraphFacebookAppID}\" />");
728 }
729
730 if (!string.IsNullOrEmpty(openGraphType))
731 {
732 Pageview.Meta.AddTag($"<meta property=\"og:type\" content=\"{openGraphType}\" />");
733 }
734
735 if (!string.IsNullOrEmpty(openGraphSiteName))
736 {
737 Pageview.Meta.AddTag($"<meta property=\"og:url\" content=\"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}{Pageview.SearchFriendlyUrl}\" />");
738 }
739
740 if (!string.IsNullOrEmpty(openGraphSiteName))
741 {
742 Pageview.Meta.AddTag($"<meta property=\"og:site_name\" content=\"{openGraphSiteName}\" />");
743 }
744
745
746 else
747 {
748 Pageview.Meta.AddTag($"<meta property=\"og:title\" content=\"{openGraphSiteTitle}\" />");
749 }
750
751 if (!string.IsNullOrEmpty(Model.Title))
752 {
753
754 if (!isProductDetailsPage)
755 {
756 Pageview.Meta.AddTag($"<meta property=\"og:title\" content=\"{Model.Title}\"");
757
758 }
759 }
760
761 if (!string.IsNullOrEmpty(twitterCardSite))
762 {
763 Pageview.Meta.AddTag("twitter:site", twitterCardSite);
764 }
765
766 if (!string.IsNullOrEmpty(twitterCardURL))
767 {
768 Pageview.Meta.AddTag("twitter:url", twitterCardURL);
769 }
770
771 if (!string.IsNullOrEmpty(twitterCardTitle))
772 {
773 Pageview.Meta.AddTag("twitter:title", twitterCardTitle);
774 }
775 }
776 }
777