Error executing template "Designs/Swift/_parsed/Swift_Page.parsed.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
at Dynamicweb.Content.Layouts.LayoutTemplateLocator.FindLayoutTemplateForPage(Page page)
at Dynamicweb.Frontend.Content.GetLayoutForDevice(Page page, DeviceType device)
at Dynamicweb.Frontend.Content.CreateGridContent(Int32 contentId, Boolean ignoreVisualEdit)
at Dynamicweb.Frontend.Content.RenderExternalGrid(Int32 pageId, String container)
at CompiledRazorTemplates.Dynamic.RazorEngine_65d0d8561fb44cd98bfd6565be0186ea.Execute() in D:\Solution\BKI LIVE\Files\Templates\Designs\Swift\_parsed\Swift_Page.parsed.cshtml:line 664
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 S_DW_BKI_Swift.CustomModules.Helpers
7 @using S_DW_BKI_Swift.CustomModules.Extensions;
8 @using S_DW_BKI_Swift.CustomModules.TemplateHelpers
9
10 @{
11 string swiftVersion = ReadFile("/Files/Templates/Designs/Swift/swift_version.txt");
12 bool renderAsResponsive = Model.Area.Item.GetString("DeviceRendering", "responsive").Equals("responsive", StringComparison.OrdinalIgnoreCase);
13 bool renderMobile = Pageview.Device == Dynamicweb.Frontend.Devices.DeviceType.Mobile || Pageview.Device == Dynamicweb.Frontend.Devices.DeviceType.Tablet;
14 string responsiveClassDesktop = string.Empty;
15 string responsiveClassMobile = string.Empty;
16 if (renderAsResponsive)
17 {
18 responsiveClassDesktop = " d-none d-xl-block";
19 responsiveClassMobile = " d-block d-xl-none";
20 }
21
22 var disableWideBreakpoints = Model.Area?.Item?.GetRawValueString("DisableWideBreakpoints", "default");
23
24 var brandingPageId = Model.Area.Item.GetLink("BrandingPage") != null ? Model.Area.Item.GetLink("BrandingPage").PageId : 0;
25 var themePageId = Model.Area.Item.GetLink("ThemesPage") != null ? Model.Area.Item.GetLink("ThemesPage").PageId : 0;
26 string customHeaderInclude = Model.Area.Item.GetFile("CustomHeaderInclude") != null ? Model.Area.Item.GetFile("CustomHeaderInclude").Name : string.Empty;
27
28 var brandingPage = Dynamicweb.Content.Services.Pages?.GetPage(brandingPageId) ?? null;
29 var themesParagraphLastChanged = Dynamicweb.Content.Services.Paragraphs.GetParagraphsByPageId(themePageId).OrderByDescending(p => p.Audit.LastModifiedAt).FirstOrDefault();
30
31 var cssLastModified = brandingPage.Audit.LastModifiedAt > themesParagraphLastChanged.Audit.LastModifiedAt ? brandingPage.Audit.LastModifiedAt : themesParagraphLastChanged.Audit.LastModifiedAt;
32 var cssThemeAndBrandingStyleFileInfo = new System.IO.FileInfo(Dynamicweb.Core.SystemInformation.MapPath($"/Files/Templates/Designs/Swift/_parsed/Swift_css/Swift_styles_{Model.Area.ID}.min.css"));
33
34
35 string productId = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString.Get("ProductID")) ? Dynamicweb.Context.Current.Request.QueryString.Get("ProductID") : "";
36 bool isProductDetailsPage = !string.IsNullOrEmpty(productId);
37 bool isArticlePage = Model.ItemType == "Swift_Article";
38 Dynamicweb.Content.PageService ps = new Dynamicweb.Content.PageService();
39 var page = ps.GetFirstPageForArea(Dynamicweb.Frontend.PageView.Current().AreaID);
40
41
42 bool isFrontpage = Dynamicweb.Frontend.PageView.Current().Page.ID == page.ID ? true : false;
43 var getSchemaParagraph = SchemaMarkupHelpers.GetParagraphById(Pageview, "ActivateSchema");
44 bool activateOrgSchema = getSchemaParagraph != null ? Convert.ToBoolean(getSchemaParagraph.Item["ShowOrganizationShema"]) : false;
45
46
47 bool showOrgSchema = false;
48 var customSettings = SchemaMarkupHelpers.GetCustomSettings(Pageview);
49
50 bool useSchema = false;
51 if (customSettings != null)
52 {
53 useSchema = customSettings.Item["ShowSchema"] != null ? Convert.ToBoolean(customSettings.Item["ShowSchema"]) : false;
54 }
55
56 string schemaOrgType = string.Empty;
57
58 if (isProductDetailsPage)
59 {
60 schemaOrgType = "itemscope=\"\" itemtype=\"https://schema.org/Product\"";
61 }
62
63 if (isArticlePage)
64 {
65 schemaOrgType = "itemscope=\"\" itemtype=\"https://schema.org/Article\"";
66 }
67
68 if (isFrontpage)
69 {
70 schemaOrgType = "itemscope=\"\" itemtype=\"https://schema.org/Organization\"";
71 }
72
73 if (!cssThemeAndBrandingStyleFileInfo.Exists || cssThemeAndBrandingStyleFileInfo.LastWriteTime < brandingPage.Audit.LastModifiedAt)
74 {
75 //Branding page has been saved or the file is missing. Rewrite the file to disc.
76 if (brandingPageId > 0)
77 {
78 var brandingPageview = Dynamicweb.Frontend.PageView.GetPageviewByPageID(brandingPageId);
79 brandingPageview.Redirect = false;
80 brandingPageview.Output();
81 }
82 }
83
84 if (!cssThemeAndBrandingStyleFileInfo.Exists || cssThemeAndBrandingStyleFileInfo.LastWriteTime < themesParagraphLastChanged.Audit.LastModifiedAt)
85 {
86 //Branding page has been saved or the file is missing. Rewrite the file to disc.
87 if (themePageId > 0)
88 {
89 var themePageview = Dynamicweb.Frontend.PageView.GetPageviewByPageID(themePageId);
90 themePageview.Redirect = false;
91 themePageview.Output();
92 }
93 }
94
95 var cssStyleFileInfo = new System.IO.FileInfo(Dynamicweb.Core.SystemInformation.MapPath("/Files/Templates/Designs/Swift/Assets/css/styles.css"));
96 var cssOverwritesFileInfo = new System.IO.FileInfo(Dynamicweb.Core.SystemInformation.MapPath("/Files/Templates/Designs/Swift/Assets/css/overwrites.css"));
97 var jsFileInfo = new System.IO.FileInfo(Dynamicweb.Core.SystemInformation.MapPath("/Files/Templates/Designs/Swift/Assets/js/scripts.js"));
98
99 string masterTheme = !string.IsNullOrWhiteSpace(Model.Area.Item.GetRawValueString("Theme")) ? " theme " + Model.Area.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : "";
100
101 string favicon = Model.Area.Item.GetFile("Favicon") != null ? Model.Area.Item.GetFile("Favicon").Path : "/Files/Templates/Designs/Swift/Assets/Images/favicon.png";
102
103 string headerCssClass = "sticky-top";
104 bool movePageBehind = false;
105
106 if (Pageview.Page.PropertyItem != null)
107 {
108 headerCssClass = Pageview.Page.PropertyItem["MoveThisPageBehindTheHeader"] != null ? Pageview.Page.PropertyItem["MoveThisPageBehindTheHeader"].ToString() : "sticky-top";
109 movePageBehind = headerCssClass == "fixed-top" && !Pageview.IsVisualEditorMode ? true : false;
110 }
111
112 headerCssClass = headerCssClass == "" ? "sticky-top" : headerCssClass;
113 headerCssClass = Pageview.IsVisualEditorMode ? "" : headerCssClass;
114
115 string googleTagManagerID = Model.Area.Item.GetString("GoogleTagManagerID");
116 string googleAnalyticsMeasurementID = Model.Area.Item.GetString("GoogleAnalyticsMeasurementID");
117 var cookieOptInLevel = CookieManager.GetCookieOptInLevel();
118 bool allowTracking = true;
119
120 Dynamicweb.Context.Current.Response.AddHeader("link", $"</Files/Templates/Designs/Swift/Assets/css/styles.css?{cssStyleFileInfo.LastWriteTime.Ticks}>; rel=preload; as=style;");
121 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;");
122 Dynamicweb.Context.Current.Response.AddHeader("link", $"</Files/Templates/Designs/Swift/Assets/js/aos.js?{jsFileInfo.LastWriteTime.Ticks}; rel=preload; as=script;");
123 Dynamicweb.Context.Current.Response.AddHeader("link", $"</Files/Templates/Designs/Swift/Assets/js/scripts.js?{jsFileInfo.LastWriteTime.Ticks}; rel=preload; as=script;");
124 //Dynamicweb.Context.Current.Response.Flush(); //This sends the headers where we are now in the rendering making the TTFB faster
125
126 SetMetaTags();
127
128 List<Dynamicweb.Content.Page> languages = new List<Dynamicweb.Content.Page>();
129
130 if (Pageview.Area.IsMaster)
131 {
132 languages.Add(Pageview.Page);
133 if (Pageview.Page.Languages != null)
134 {
135 foreach (var language in Pageview.Page.Languages)
136 {
137 languages.Add(language);
138 }
139 }
140 }
141 else
142 {
143 languages.Add(Pageview.Page.MasterPage);
144 if (Pageview.Page.MasterPage != null)
145 {
146 if (Pageview.Page.MasterPage.Languages != null)
147 {
148 foreach (var language in Pageview.Page.MasterPage.Languages)
149 {
150 languages.Add(language);
151 }
152 }
153 }
154 }
155
156 string siteLanguage = Pageview.Area.CultureInfo.Name;
157 Uri url = Dynamicweb.Context.Current.Request.Url;
158 string hostName = url.Host; // domain.com/da-dk or domain.com/en-us
159
160 var ecomCountries = Dynamicweb.Ecommerce.Services.Countries.GetCountries();
161 var ecomCurrencies = Dynamicweb.Ecommerce.Services.Currencies.GetAllCurrencies();
162
163 // CUSTOM ADD START
164 string customHeadScripts = CustomSettingsHelper.GetSetting<string>("CustomHeadScripts");
165 string customBodyScripts = CustomSettingsHelper.GetSetting<string>("CustomBodyScripts");
166 bool renderCustomHeadScripts = !string.IsNullOrEmpty(customHeadScripts);
167 bool renderCustomBodyScripts = !string.IsNullOrEmpty(customBodyScripts);
168
169 var currentPage = S_DW_BKI_Swift.CustomModules.Helpers.TemplateHelper.GetCurrentPage();
170 var isBCRpage = S_DW_BKI_Swift.CustomModules.Helpers.TemplateHelper.IsBCRPage(currentPage);
171 // CUSTOM ADD END
172 }
173 <!doctype html>
174 <html lang="@Pageview.Area.CultureInfo.TwoLetterISOLanguageName">
175 <head>
176 <!-- @swiftVersion -->
177 @if (renderCustomHeadScripts)
178 {
179 @customHeadScripts
180 }
181 @* Required meta tags *@
182 <meta charset="utf-8">
183 <meta name="viewport" content="height=device-height, width=device-width, initial-scale=1.0">
184 <link rel="shortcut icon" href="@favicon">
185 @*custom edit start*@
186 @if (isFrontpage && useSchema || activateOrgSchema && useSchema)
187 {
188 @SchemaMarkupHelpers.GetSchemaMarkupForOrganization(customSettings, Pageview)
189 }
190
191 @if (isArticlePage && useSchema)
192 {
193 @SchemaMarkupHelpers.GetSchemaMarkupForArticle(customSettings, Pageview)
194
195 }
196
197 @if (isProductDetailsPage && useSchema)
198 {
199 @SchemaMarkupHelpers.GetSchemaMarkupForProduct(customSettings, Pageview, productId)
200 }
201
202 @if (!string.IsNullOrEmpty(favicon))
203 {
204 <link rel="apple-touch-icon" href="@favicon">
205 }
206
207
208 @RenderSnippet("videoSchema")
209 @RenderSnippet("recipeSchema")
210 <link rel="canonical" href="@Pageview.GetCanonical()">
211
212 @*Custom Scripts*@
213 @{
214 var headscripts = Pageview.Page.PropertyItem != null && Pageview.Page.PropertyItem["HeadScripts"] != null ? Pageview.Page.PropertyItem["HeadScripts"].ToString() : "";
215
216
217 if (headscripts != null && !string.IsNullOrEmpty(headscripts.ToString()))
218 {
219 @headscripts
220
221 }
222 }
223
224
225 @*Add noindex nofollow on category pages but check first if added already*@
226
227 @if (!Model.MetaTags.Contains("<meta name=\"robots\" content=\"noindex,nofollow\">"))
228 {
229 @RenderSnippet("robotsProductList")
230 @Model.MetaTags
231
232
233 }
234 else
235 {
236 @Model.MetaTags}
237
238
239 @{
240 var alreadyWrittenTwoletterIsos = new List<string>();
241 @* Languages meta data *@
242 foreach (var language in languages)
243 {
244 hostName = url.Host;
245 if (language?.Area != null)
246 {
247 if (language.Area?.MasterArea != null && !string.IsNullOrEmpty(language.Area.MasterArea.DomainLock))
248 {
249 hostName = language.Area.MasterArea.DomainLock; //dk.domain.com or dk-domain.dk
250 }
251 if (language != null && language.Published && language.Area.Active && language.Area.Published)
252 {
253 if (!string.IsNullOrEmpty(language.Area.DomainLock))
254 {
255 hostName = language.Area.DomainLock; //dk.domain.com or dk-domain.dk
256 }
257 string querystring = $"Default.aspx?ID={language.ID}";
258 if (!string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString["GroupID"]))
259 {
260 querystring += $"&GroupID={Dynamicweb.Context.Current.Request.QueryString["GroupID"]}";
261 }
262 if (!string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString["ProductID"]))
263 {
264 querystring += $"&ProductID={Dynamicweb.Context.Current.Request.QueryString["ProductID"]}";
265 }
266 if (!string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString["VariantID"]))
267 {
268 querystring += $"&VariantID={Dynamicweb.Context.Current.Request.QueryString["VariantID"]}";
269 }
270
271 string friendlyUrl = Dynamicweb.Frontend.SearchEngineFriendlyURLs.GetFriendlyUrl(querystring);
272 if (language.Area.RedirectFirstPage && language.ParentPageId == 0 && language.Sort == 1)
273 {
274 friendlyUrl = "/";
275 }
276 string href = $"{url.Scheme}://{hostName}{friendlyUrl}";
277
278
279 <link rel="alternate" hreflang="@language.Area.CultureInfo.Name.ToLower()" href="@href">
280 if (!alreadyWrittenTwoletterIsos.Contains(language.Area.CultureInfo.TwoLetterISOLanguageName))
281 {
282 <link rel="alternate" hreflang="@language.Area.CultureInfo.TwoLetterISOLanguageName.ToLower()" href="@href">
283 }
284 }
285 }
286 }
287 }
288
289 <title>@Model.Title</title>
290 @* Bootstrap + Swift stylesheet *@
291 <link href="/Files/Templates/Designs/Swift/Assets/css/styles.css?@cssStyleFileInfo.LastWriteTime.Ticks" rel="stylesheet" media="all" type="text/css">
292
293 @if (disableWideBreakpoints != "disableBoth")
294 {
295 <style>
296 @@media ( min-width: 1600px ) {
297 .container-xxl,
298 .container-xl,
299 .container-lg,
300 .container-md,
301 .container-sm,
302 .container {
303 max-width: 1520px;
304 }
305 }
306 </style>
307
308
309
310 if (disableWideBreakpoints != "disableUltraWideOnly")
311 {
312 <style>
313 @@media ( min-width: 1920px ) {
314 .container-xxl,
315 .container-xl,
316 .container-lg,
317 .container-md,
318 .container-sm,
319 .container {
320 max-width: 1820px;
321 }
322 }
323 </style>
324 }
325 }
326
327 @* Branding and Themes min stylesheet *@
328 <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">
329 @* Custom overwrites stylesheet *@
330 <link href="/Files/Templates/Designs/Swift/Assets/css/overwrites.css?@cssOverwritesFileInfo.LastWriteTime.Ticks" rel="stylesheet" media="all" type="text/css">
331 <script src="/Files/Templates/Designs/Swift/Assets/js/aos.js?@jsFileInfo.LastWriteTime.Ticks" defer></script>
332 <script src="/Files/Templates/Designs/Swift/Assets/js/scripts.js?@jsFileInfo.LastWriteTime.Ticks" defer></script>
333
334 <script type="module">
335 AOS.init({ duration: 400, delay: 100, easing: 'ease-in-out', mirror: false, disable: window.matchMedia('(prefers-reduced-motion: reduce)') });
336 swift.Scroll.hideHeadersOnScroll();
337 swift.Scroll.handleAlternativeTheme();
338 </script>
339
340 @* Google tag manager *@
341 @if (!string.IsNullOrWhiteSpace(googleTagManagerID) && allowTracking)
342 {
343 <script>
344 @if (!renderCustomHeadScripts)
345 {
346 <text>
347 (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
348 new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
349 j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
350 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
351 })(window, document, 'script', 'dataLayer', '@(googleTagManagerID)');
352 </text>
353 }
354
355 function gtag() {
356 if (dataLayer) {
357 dataLayer.push(arguments);
358 }
359 }
360 </script>
361 }
362
363 @if (!string.IsNullOrWhiteSpace(googleAnalyticsMeasurementID) && allowTracking)
364 {
365 var GoogleAnalyticsDebugMode = "";
366 bool isLoggedInBackendUser = false;
367
368 if (Dynamicweb.Security.UserManagement.User.GetCurrentBackendUser() != null)
369 {
370 isLoggedInBackendUser = true;
371 }
372
373 if (Model.Area.Item.GetBoolean("EnableGoogleAnalyticsDebugMode") && isLoggedInBackendUser)
374 {
375 GoogleAnalyticsDebugMode = ", {'debug_mode': true}";
376 }
377
378 <script async src="https://www.googletagmanager.com/gtag/js?id=@googleAnalyticsMeasurementID"></script>
379 <script>
380 window.dataLayer = window.dataLayer || [];
381 function gtag() {
382 if (dataLayer) {
383 dataLayer.push(arguments);
384 }
385 }
386 gtag('js', new Date());
387 gtag('config', '@googleAnalyticsMeasurementID'@GoogleAnalyticsDebugMode);
388 </script>
389 }
390
391 @if (!string.IsNullOrWhiteSpace(customHeaderInclude) && !isBCRpage)
392 {
393 @RenderPartial($"Components/Custom/{customHeaderInclude}")
394 }
395
396 @if (isBCRpage)
397 {
398 <link rel="stylesheet" href=https://use.typekit.net/jbn6ewy.css>
399 <style>
400 main {
401 font-family: "tomarik-poster", sans-serif !important;
402 }
403
404 main h1, main h2, main h3, main h4, main h5, main h6,
405 main .h1, main .h2, main .h3, main .h4, main .h5, main .h6,
406 main .display-1, main .display-2, main .display-3,
407 main .display-4, main .display-5, main .display-6 {
408 font-family: "citrus-gothic-solid", sans-serif !important;
409 }
410
411 @@font-face {
412 font-family: 'Gotham Book';
413 src: url('/Files/Templates/Designs/Swift/Assets/fonts/gotham-book.woff');
414 font-weight: normal;
415 font-style: normal;
416 }
417
418 main .gotham h3, main .gotham p, main .gotham p span {
419 text-align: center;
420 font-weight: 600;
421 font-style: normal;
422 font-family: 'Gotham Book', sans-serif !important;
423 --swift-font-family: 'Gotham Book', sans-serif !important;
424 }
425
426 ul.slideralignement-left {
427 justify-content: left;
428 }
429
430 ul.slideralignement-center {
431 justify-content: center;
432 }
433
434 ul.slideralignement-right {
435 justify-content: right;
436 }
437
438
439 </style>
440 }
441 @{
442 Dictionary<int, string> labelList = new Dictionary<int, string>();
443 var customSettingsItem = Dynamicweb.Content.Services.Pages.GetPageByNavigationTag(Pageview.AreaID, "CustomSettings")?.Item;
444 if (customSettingsItem != null)
445 {
446 labelList = CheckoutTemplateHelper.GetSignLabelItemList(customSettingsItem);
447 }
448 }
449 <script>
450 window.Translations = {
451 AddNewOrderLine: '@Translate("Add new order line")',
452 WithDescription: "@Translate("With description")",
453 WithoutDescription: "@Translate("Without description")",
454 WithSign: "@Translate("With sign")",
455 Sign: "@Translate("Sign")",
456 Yes: "@Translate("Yes")",
457 No: "@Translate("No")",
458 None: "@Translate("None")",
459 };
460
461 window.POSMaterials = {};
462 @foreach (var label in labelList)
463 {
464 <text>
465 POSMaterials['@label.Key'] = "@label.Value";
466 </text>
467 }
468
469 </script>
470 </head>
471 <body class="brand @(masterTheme)" id="page@(Model.ID)">
472 @* CUSTOM EDIT START *@
473 @if (renderCustomBodyScripts)
474 {
475 @customBodyScripts
476 }
477 else
478 {
479 @* Google tag manager *@
480 if (!string.IsNullOrWhiteSpace(googleTagManagerID) && allowTracking)
481 {
482 <noscript>
483 <iframe src="https://www.googletagmanager.com/ns.html?id=@(googleTagManagerID)"
484 height="0" width="0" style="display:none;visibility:hidden"></iframe>
485 </noscript>
486 }
487 }
488 @* CUSTOM EDIT END *@
489
490 @if (renderAsResponsive || !renderMobile)
491 {
492 <header class="page-header @headerCssClass top-0@(responsiveClassDesktop)" id="page-header-desktop">
493 @if (@Model.Area.Item.GetLink("HeaderDesktop") != null)
494 {
495 @RenderGrid(@Model.Area.Item.GetLink("HeaderDesktop").PageId)
496 }
497 </header>
498 }
499
500 @if ((renderAsResponsive || renderMobile))
501 {
502 <header class="page-header @headerCssClass top-0@(responsiveClassMobile)" id="page-header-mobile">
503 @if (@Model.Area.Item.GetLink("HeaderMobile") != null)
504 {
505 @RenderGrid(@Model.Area.Item.GetLink("HeaderMobile").PageId)
506 }
507 </header>
508 }
509
510 <main id="content" @(schemaOrgType)>
511 <div data-intersect></div>
512 @inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.PageViewModel>
513 @using System
514 @using Dynamicweb.Ecommerce.ProductCatalog
515
516
517 @{
518 string productIdFromUrl = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString.Get("ProductID")) ? Dynamicweb.Context.Current.Request.QueryString.Get("ProductID") : string.Empty;
519 bool isProductDetail = !string.IsNullOrEmpty(productIdFromUrl) && new[] { "shop", "shopanonymous" }.Contains(Pageview.Page.NavigationTag.ToLower()); // CUSTOM EDIT
520
521 bool isArticlePagePage = Model.ItemType == "Swift_Article";
522 bool isArticleListPage = Model.ItemType == "Swift_ArticleListPage";
523 string schemaOrgProp = string.Empty;
524 if(isArticlePagePage)
525 {
526 schemaOrgProp = "itemprop=\"articleBody\"";
527 }
528
529 string theme = "";
530 string gridContent = "";
531
532 if (Model.PropertyItem != null)
533 {
534 theme = !string.IsNullOrWhiteSpace(Model.PropertyItem.GetRawValueString("Theme")) ? "theme " + Model.PropertyItem.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : "";
535 }
536
537 if (Model.Item != null || Pageview.IsVisualEditorMode)
538 {
539 if (!isProductDetail)
540 {
541 gridContent = Model.Grid("Grid", "Grid", "default:true;sort:1", "Page");
542 }
543 else
544 {
545 var productObject = Dynamicweb.Ecommerce.Services.Products.GetProductById(productIdFromUrl, "", Pageview.Area.EcomLanguageId);
546 var detailPage = Dynamicweb.Ecommerce.Services.ProductGroups.GetGroup(productObject.PrimaryGroupId)?.Meta.PrimaryPage ?? string.Empty;
547 var detailPageId = detailPage != string.Empty ? Convert.ToInt16(detailPage.Substring(detailPage.LastIndexOf('=') + 1)) : GetPageIdByNavigationTag("ProductDetailPage");
548
549 @RenderGrid(detailPageId)
550 }
551 }
552
553 bool doNotRenderPage = false;
554
555 //Check if we are on the poduct detail page, and if there is data to render
556 ProductViewModel product = new ProductViewModel();
557 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails"))
558 {
559 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"];
560 if (string.IsNullOrEmpty(product.Id)) {
561 doNotRenderPage = true;
562 }
563 }
564
565 //Render the page
566 if (!doNotRenderPage) {
567 string itemIdentifier = Model?.Item?.SystemName != null ? "item_" + Model.Item.SystemName.ToLower() : "item_Swift_Page";
568
569
570 <div class="@theme @itemIdentifier" @schemaOrgProp>
571 @if (isArticleListPage)
572 {
573 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\"";
574
575 <form @hx id="ArticleFacetForm">
576 @gridContent
577 </form>
578 <script type="module" src="/Files/Templates/Designs/Swift/Assets/js/htmx.js"></script>
579 <script type="module">
580 document.addEventListener('htmx:confirm', (event) => {
581 let filters = event.detail.elt.querySelectorAll('select');
582 for (var i = 0; i < filters.length; i++) {
583 let input = filters[i];
584 if (input.name && !input.value) {
585 input.name = '';
586 }
587 }
588 });
589
590 document.addEventListener('htmx:beforeOnLoad', (event) => {
591 swift.Scroll.stopIntersectionObserver();
592 });
593
594 document.addEventListener('htmx:afterOnLoad', () => {
595 swift.Scroll.hideHeadersOnScroll();
596 swift.Scroll.handleAlternativeTheme();
597 });
598 </script>
599 }
600 else
601 {
602 @gridContent
603 }
604 </div>
605
606 } else {
607 <div class="container">
608 <div class="alert alert-info" role="alert">@Translate("Sorry. There is nothing to view here")</div>
609 </div>
610 }
611
612 if (!Model.IsCurrentUserAllowed)
613 {
614 int signInPage = GetPageIdByNavigationTag("SignInPage");
615 int dashboardPage = GetPageIdByNavigationTag("MyAccountDashboardPage");
616
617 if (!Pageview.IsVisualEditorMode)
618 {
619 if (signInPage != 0)
620 {
621 if (signInPage != Model.ID) {
622 Dynamicweb.Context.Current.Response.Redirect("/Default.aspx?ID=" + signInPage);
623 } else {
624 if (dashboardPage != 0) {
625 Dynamicweb.Context.Current.Response.Redirect("/Default.aspx?ID=" + dashboardPage);
626 } else {
627 Dynamicweb.Context.Current.Response.Redirect("/");
628 }
629 }
630 }
631 else
632 {
633 <div class="alert alert-dark m-0" role="alert">
634 <span>@Translate("You do not have access to this page")</span>
635 </div>
636 }
637 }
638 else
639 {
640 <div class="alert alert-dark m-0" role="alert">
641 <span>@Translate("To work on this page, you must be signed in, in the frontend")</span>
642 </div>
643 }
644 }
645 }
646
647 </main>
648
649 @if (renderAsResponsive || !renderMobile)
650 {
651 <footer class="page-footer@(responsiveClassDesktop)" id="page-footer-desktop">
652 @if (@Model.Area.Item.GetLink("FooterDesktop") != null)
653 {
654 @RenderGrid(@Model.Area.Item.GetLink("FooterDesktop").PageId)
655 }
656 </footer>
657 }
658
659 @if (renderAsResponsive || renderMobile)
660 {
661 <footer class="page-footer@(responsiveClassMobile)" id="page-footer-mobile">
662 @if (@Model.Area.Item.GetLink("FooterMobile") != null)
663 {
664 @RenderGrid(@Model.Area.Item.GetLink("FooterMobile").PageId)
665 }
666 </footer>
667 }
668
669 @* Render any offcanvas menu here *@
670 @RenderSnippet("offcanvas")
671
672 @{
673 bool isErpConnectionDown = !Dynamicweb.Core.Converter.ToBoolean(Context.Current.Items["IsWebServiceConnectionAvailable"]);
674 }
675
676 @* Language selector modal *@
677 @if (languages.Count > 1 || ecomCountries.Count > 1 || ecomCurrencies.Count() > 1)
678 {
679 <div class="modal fade" id="PreferencesModal" tabindex="-1" aria-hidden="true">
680 <div class="modal-dialog modal-dialog-centered modal-sm" id="PreferencesModalContent">
681 @* The content here comes from an external request *@
682 </div>
683 </div>
684 }
685
686 @* Favorite toast *@
687 <div aria-live="polite" aria-atomic="true">
688 <div class="position-fixed bottom-0 end-0 p-3" style="z-index: 11">
689 <div id="favoriteNotificationToast" class="toast" role="alert" aria-live="assertive" aria-atomic="true">
690 <div class="toast-header">
691 <strong class="me-auto">@Translate("Favorite list updated")</strong>
692 <button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
693 </div>
694 <div class="toast-body d-flex gap-3">
695 <div id="favoriteNotificationToast_Image"></div>
696 <div id="favoriteNotificationToast_Text"></div>
697 </div>
698 </div>
699 </div>
700 </div>
701
702 @* Modal for dynamic content *@
703 <div class="modal fade js-product" id="DynamicModal" tabindex="-1" aria-hidden="true">
704 <div class="modal-dialog modal-dialog-centered modal-md">
705 <div class="modal-content theme light" id="DynamicModalContent">
706 @* The content here comes from an external request *@
707 </div>
708 </div>
709 </div>
710
711 @* Offcanvas for dynamic content *@
712 <div class="offcanvas offcanvas-end theme light" tabindex="-1" id="DynamicOffcanvas" style="width: 30rem">
713 @* The content here comes from an external request *@
714 </div>
715
716 @if (isErpConnectionDown && Model.Area.Item.GetBoolean("ShowErpDownMessage"))
717 {
718 string erpDownMessageTheme = !string.IsNullOrWhiteSpace(Model.Area.Item.GetRawValueString("ErpDownMessageTheme")) ? " theme " + Model.Area.Item.GetRawValueString("ErpDownMessageTheme").Replace(" ", "").Trim().ToLower() : "theme light";
719
720 <div class="position-fixed bottom-0 end-0 p-3" style="z-index: 1040">
721 <div class="toast fade show border-0 @erpDownMessageTheme" role="alert" aria-live="assertive" aria-atomic="true">
722 <div class="toast-header">
723 <strong class="me-auto">@Translate("Connection down")</strong>
724 <button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
725 </div>
726 <div class="toast-body">
727 @Translate("We are experiencing some connectivity issues. Not all features may be available to you.")
728 </div>
729 </div>
730 </div>
731 }
732 </body>
733 </html>
734 @functions {
735 void SetMetaTags()
736 {
737 //Verification Tokens
738 string siteVerificationGoogle = Model.Area.Item.GetString("Google_Site_Verification") != null ? Model.Area.Item.GetString("Google_Site_Verification") : "";
739 //string siteVerificationYandex = Model.Area.Item.GetString("Yandex_Verification") != null ? Model.Area.Item.GetString("Yandex_Verification") : "";
740 //string siteVerificationMS = Model.Area.Item.GetString("Msvalidate_01") != null ? Model.Area.Item.GetString("Msvalidate_01") : "";
741 //string siteVerificationAlexa = Model.Area.Item.GetString("AlexaVerifyID") != null ? Model.Area.Item.GetString("AlexaVerifyID") : "";
742 //string siteVerificationPinterest = Model.Area.Item.GetString("P_domain_verify") != null ? Model.Area.Item.GetString("P_domain_verify") : "";
743 //string siteVerificationNorton = Model.Area.Item.GetString("Norton_safeweb_site_verification") != null ? Model.Area.Item.GetString("Norton_safeweb_site_verification") : "";
744
745 //Generic Site Values
746 string openGraphFacebookAppID = Model.Area.Item.GetString("Fb_app_id") != null ? Model.Area.Item.GetString("Fb_app_id") : "";
747 string openGraphType = Model.Area.Item.GetString("Open_Graph_Type") != null ? Model.Area.Item.GetString("Open_Graph_Type") : "";
748 string openGraphSiteName = Model.Area.Item.GetString("Open_Graph_Site_Name") != null ? Model.Area.Item.GetString("Open_Graph_Site_Name") : "";
749
750 string twitterCardSite = Model.Area.Item.GetString("Twitter_Site") != null ? Model.Area.Item.GetString("Twitter_Site") : "";
751
752 //Page specific values
753 string openGraphSiteTitle = Model.Area.Item.GetString("Open_Graph_Title") != null ? Model.Area.Item.GetString("Open_Graph_Title") : "";
754 FileViewModel openGraphImage = Model.Area.Item.GetFile("Open_Graph_Image");
755 string openGraphImageALT = Model.Area.Item.GetString("Open_Graph_Image_ALT") != null ? Model.Area.Item.GetString("Open_Graph_Image_ALT") : "";
756 string openGraphDescription = Model.Area.Item.GetString("Open_Graph_Description") != null ? Model.Area.Item.GetString("Open_Graph_Description") : "";
757
758 string twitterCardURL = Model.Area.Item.GetString("Twitter_URL") != null ? Model.Area.Item.GetString("Twitter_URL") : "";
759 string twitterCardTitle = Model.Area.Item.GetString("Twitter_Title") != null ? Model.Area.Item.GetString("Twitter_Title") : "";
760 string twitterCardDescription = Model.Area.Item.GetString("Twitter_Description") != null ? Model.Area.Item.GetString("Twitter_Description") : "";
761 FileViewModel twitterCardImage = Model.Area.Item.GetFile("Twitter_Image");
762 string twitterCardImageALT = Model.Area.Item.GetString("Twitter_Image_ALT") != null ? Model.Area.Item.GetString("Twitter_Image_ALT") : "";
763
764 if (string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString["ProductID"]))
765 {
766 if (!string.IsNullOrEmpty(Model.Description))
767 {
768 Pageview.Meta.AddTag($"<meta property=\"og:description\" content=\"{Model.Description}\" />");
769 }
770 else
771 {
772 Pageview.Meta.AddTag($"<meta property=\"og:description\" content=\"{openGraphDescription}\" />");
773 }
774
775 if (!string.IsNullOrEmpty(Pageview.Page.TopImage))
776 {
777 Pageview.Meta.AddTag($"<meta property=\"og:image\" content=\"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}/Files{Pageview.Page.TopImage}\" />");
778 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}\" />");
779 }
780 else if (openGraphImage != null)
781 {
782 Pageview.Meta.AddTag($"<meta property=\"og:image\" content=\"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}{openGraphImage.Path}\" />");
783 Pageview.Meta.AddTag($"<meta property=\"og:image:secure_url\" content=\"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}{openGraphImage.Path}\" />");
784 }
785
786 if (!string.IsNullOrEmpty(openGraphImageALT))
787 {
788 Pageview.Meta.AddTag($"<meta property=\"og:image:alt\" content=\"{openGraphImageALT}\"/>");
789 }
790 if (!string.IsNullOrEmpty(twitterCardDescription))
791 {
792 Pageview.Meta.AddTag("twitter:description", twitterCardDescription);
793 }
794
795 if (!string.IsNullOrEmpty(Pageview.Page.TopImage))
796 {
797 Pageview.Meta.AddTag("twitter:image", $"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}/Files{Pageview.Page.TopImage}");
798 }
799 else if (twitterCardImage != null)
800 {
801 Pageview.Meta.AddTag("twitter:image", $"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}{openGraphImage.Path}");
802 }
803
804 if (!string.IsNullOrEmpty(twitterCardImageALT))
805 {
806 Pageview.Meta.AddTag("twitter:image:alt", twitterCardImageALT);
807 }
808 }
809
810 if (!string.IsNullOrEmpty(siteVerificationGoogle))
811 {
812 Pageview.Meta.AddTag("google-site-verification", siteVerificationGoogle);
813 }
814
815 if (!string.IsNullOrEmpty(openGraphFacebookAppID))
816 {
817 Pageview.Meta.AddTag($"<meta property=\"fb:app_id\" content=\"{openGraphFacebookAppID}\" />");
818 }
819
820 if (!string.IsNullOrEmpty(openGraphType))
821 {
822 Pageview.Meta.AddTag($"<meta property=\"og:type\" content=\"{openGraphType}\" />");
823 }
824
825 if (!string.IsNullOrEmpty(openGraphSiteName))
826 {
827 Pageview.Meta.AddTag($"<meta property=\"og:url\" content=\"{Dynamicweb.Context.Current.Request.Url.Scheme}://{Dynamicweb.Context.Current.Request.Url.Host}{Pageview.SearchFriendlyUrl}\" />");
828 }
829
830 if (!string.IsNullOrEmpty(openGraphSiteName))
831 {
832 Pageview.Meta.AddTag($"<meta property=\"og:site_name\" content=\"{openGraphSiteName}\" />");
833 }
834
835 if (!string.IsNullOrEmpty(Model.Title))
836 {
837 Pageview.Meta.AddTag($"<meta property=\"og:title\" content=\"{Model.Title}\"/>");
838 }
839 else
840 {
841 Pageview.Meta.AddTag($"<meta property=\"og:title\" content=\"{openGraphSiteTitle}\" />");
842 }
843
844 if (!string.IsNullOrEmpty(twitterCardSite))
845 {
846 Pageview.Meta.AddTag("twitter:site", twitterCardSite);
847 }
848
849 if (!string.IsNullOrEmpty(twitterCardURL))
850 {
851 Pageview.Meta.AddTag("twitter:url", twitterCardURL);
852 }
853
854 if (!string.IsNullOrEmpty(twitterCardTitle))
855 {
856 Pageview.Meta.AddTag("twitter:title", twitterCardTitle);
857 }
858 }
859 }
860