Error executing template "Designs/Swift/Swift_PageNoLayout.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
at CompiledRazorTemplates.Dynamic.RazorEngine_61fdbe46f8084bdab0e1fbfdefc6821b.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.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.DynamicWrapperService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineServiceExtensions.RunCompile(IRazorEngineService service, String name, 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 RazorEngine.Templating.RazorEngineServiceExtensions.RunCompile(IRazorEngineService service, String name, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineServiceExtensions.RunCompile(IRazorEngineService service, String templateSource, 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 Dynamicweb
3 @using Dynamicweb.Environment
4 5 @functions {
6 string GetCookieOptInPermission(string category)
7 {
8 bool categoryOrAllGranted = false;
9 10 if (CookieManager.IsCookieManagementActive)
11 {
12 var cookieOptInLevel = CookieManager.GetCookieOptInLevel();
13 var cookieOptInCategories = CookieManager.GetCookieOptInCategories();
14 categoryOrAllGranted = cookieOptInCategories.Contains(category) || cookieOptInLevel == CookieOptInLevel.All;
15 }
16 17 return categoryOrAllGranted ? "granted" : "denied";
18 }
19 20 bool AllowTracking()
21 {
22 bool allowTracking = true;
23 if (CookieManager.IsCookieManagementActive)
24 {
25 var cookieOptInLevel = CookieManager.GetCookieOptInLevel();
26 var cookieOptInCategories = CookieManager.GetCookieOptInCategories();
27 28 bool consentEither = (cookieOptInCategories.Contains("Statistical") || cookieOptInCategories.Contains("Marketing"));
29 bool consentFunctional = cookieOptInLevel == CookieOptInLevel.Functional;
30 bool consentAtLeastOne = cookieOptInLevel == CookieOptInLevel.All || (consentFunctional && consentEither);
31 32 allowTracking = consentAtLeastOne;
33 }
34 return allowTracking;
35 }
36 }
37 38 @{
39 string swiftVersion = ReadFile("/Files/Templates/Designs/Swift/swift_version.txt");
40 @* Branding Themes Fonts *@
41 var brandingPageId = Model.Area.Item.GetLink("BrandingPage") != null ? Model.Area.Item.GetLink("BrandingPage").PageId : 0;
42 var themePageId = Model.Area.Item.GetLink("ThemesPage") != null ? Model.Area.Item.GetLink("ThemesPage").PageId : 0;
43 44 var disableWideBreakpoints = Model.Area?.Item?.GetRawValueString("DisableWideBreakpoints", "default");
45 46 string customHeaderInclude = Model.Area.Item.GetFile("CustomHeaderInclude") != null ? Model.Area.Item.GetFile("CustomHeaderInclude").Name : string.Empty;
47 48 string masterTheme = !string.IsNullOrWhiteSpace(Model.Area.Item.GetRawValueString("Theme")) ? " theme " + Model.Area.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : "";
49 50 string favicon = Model.Area.Item.GetFile("Favicon") != null ? Model.Area.Item.GetFile("Favicon").Path : "/Files/Templates/Designs/Swift/Assets/Images/favicon.png";
51 52 var brandingPage = Dynamicweb.Content.Services.Pages?.GetPage(brandingPageId) ?? null;
53 var themesParagraphLastChanged = Dynamicweb.Content.Services.Paragraphs.GetParagraphsByPageId(themePageId).OrderByDescending(p => p.Audit.LastModifiedAt).FirstOrDefault();
54 var cssLastModified = brandingPage.Audit.LastModifiedAt > themesParagraphLastChanged.Audit.LastModifiedAt ? brandingPage.Audit.LastModifiedAt : themesParagraphLastChanged.Audit.LastModifiedAt;
55 56 var cssStyleFileInfo = new System.IO.FileInfo(Dynamicweb.Core.SystemInformation.MapPath("/Files/Templates/Designs/Swift/Assets/css/styles.css"));
57 var jsFileInfo = new System.IO.FileInfo(Dynamicweb.Core.SystemInformation.MapPath("/Files/Templates/Designs/Swift/Assets/js/scripts.js"));
58 59 string googleTagManagerID = Model.Area.Item.GetString("GoogleTagManagerID");
60 string googleAnalyticsMeasurementID = Pageview.AreaSettings.GetString("GoogleAnalyticsMeasurementID");
61 62 bool allowTracking = AllowTracking();
63 64 // Schema.org details for PDP
65 string productId = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString.Get("ProductID")) ? Dynamicweb.Context.Current.Request.QueryString.Get("ProductID") : "";
66 bool isProductDetailsPage = !string.IsNullOrEmpty(productId);
67 bool isArticlePage = Model.ItemType == "Swift_Article";
68 string schemaOrgType = string.Empty;
69 70 if (isProductDetailsPage)
71 {
72 schemaOrgType = "itemscope=\"\" itemtype=\"https://schema.org/Product\"";
73 }
74 75 if (isArticlePage)
76 {
77 schemaOrgType = "itemscope=\"\" itemtype=\"https://schema.org/Article\"";
78 }
79 }
80 81 <!doctype html>
82 <html lang="@Pageview.Area.CultureInfo.TwoLetterISOLanguageName">
83 <head>
84 <!-- @swiftVersion -->
85 @* Required meta tags *@
86 <meta charset="utf-8">
87 <meta name="viewport" content="height=device-height, width=device-width, initial-scale=1.0">
88 <link rel="preload" href="/Files/Templates/Designs/Swift/Assets/css/styles.css?@cssStyleFileInfo.LastWriteTime.Ticks" as="style">
89 <link rel="preload" href="/Files/Templates/Designs/Swift/Assets/js/scripts.js?@jsFileInfo.LastWriteTime.Ticks" as="script">
90 91 <link rel="shortcut icon" href="@favicon">
92 <link rel="apple-touch-icon" href="/Files/Templates/Designs/Swift/Assets/Images/logo_transparent.png">
93 <meta http-equiv="X-UA-Compatible" content="ie=edge">
94 <meta name="googlebot-news" content="nosnippet">
95 96 @Model.MetaTags
97 98 <title>@Model.Title</title>
99100 @* Bootstrap + Swift stylesheet *@
101 <link href="/Files/Templates/Designs/Swift/Assets/css/styles.css?@cssStyleFileInfo.LastWriteTime.Ticks" rel="stylesheet" media="all" type="text/css">
102103 @if (disableWideBreakpoints != "disableBoth")
104 {
105 <style>
106 @@media ( min-width: 1600px ) {
107 .container-xxl,
108 .container-xl,
109 .container-lg,
110 .container-md,
111 .container-sm,
112 .container {
113 max-width: 1520px;
114 }
115 }
116 </style>
117118 if (disableWideBreakpoints != "disableUltraWideOnly")
119 {
120 <style>
121 @@media ( min-width: 1920px ) {
122 .container-xxl,
123 .container-xl,
124 .container-lg,
125 .container-md,
126 .container-sm,
127 .container {
128 max-width: 1820px;
129 }
130 }
131 </style>
132 }
133 }
134135 @* Branding and Themes min stylesheet *@
136 <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">
137 <script src="/Files/Templates/Designs/Swift/Assets/js/scripts.js?@jsFileInfo.LastWriteTime.Ticks"></script>
138139 <script type="module">
140 swift.Scroll.hideHeadersOnScroll();
141 swift.Scroll.handleAlternativeTheme();
142143 //Only load if AOS
144 const aosColumns = document.querySelectorAll('[data-aos]');
145 if (aosColumns.length > 0) {
146 swift.AssetLoader.Load('/Files/Templates/Designs/Swift/Assets/js/aos.js?@jsFileInfo.LastWriteTime.Ticks', 'js');
147 document.addEventListener('load.swift.assetloader', function () {
148 AOS.init({ duration: 400, delay: 100, easing: 'ease-in-out', mirror: false, disable: window.matchMedia('(prefers-reduced-motion: reduce)') });
149 });
150 }
151 </script>
152153 @* Google gtag method - always include even if it is not used for anything *@
154 <script>
155 window.dataLayer = window.dataLayer || [];
156 function gtag() { dataLayer.push(arguments); }
157 </script>
158 @* Google tag manager *@
159 @if (!string.IsNullOrWhiteSpace(googleTagManagerID))
160 {
161 <script>
162 gtag('consent', 'default', {
163 'ad_storage': 'denied',
164 'ad_user_data': 'denied',
165 'ad_personalization': 'denied',
166 'analytics_storage': 'denied'
167 });
168 </script>
169 <script>
170 (function (w, d, s, l, i) {
171 w[l] = w[l] || []; w[l].push({
172 'gtm.start':
173 new Date().getTime(), event: 'gtm.js'
174 }); var f = d.getElementsByTagName(s)[0],
175 j = d.createElement(s), dl = l != 'dataLayer' ? '&l=' + l : ''; j.async = true; j.src =
176 'https://www.googletagmanager.com/gtm.js?id=' + i + dl; f.parentNode.insertBefore(j, f);
177 })(window, document, 'script', 'dataLayer', '@(googleTagManagerID)');
178 </script>
179 if (allowTracking)
180 {
181 string adConsent = GetCookieOptInPermission("Marketing");
182 string analyticsConsent = GetCookieOptInPermission("Statistical");
183 <script>
184 gtag('consent', 'update', {
185 'ad_storage': '@adConsent',
186 'ad_user_data': '@adConsent',
187 'ad_personalization': '@adConsent',
188 'analytics_storage': '@analyticsConsent'
189 });
190 </script>
191 }
192 }
193194 @if (!string.IsNullOrWhiteSpace(googleAnalyticsMeasurementID) && allowTracking)
195 {
196 var GoogleAnalyticsDebugMode = "";
197198 if (Model.Area.Item.GetBoolean("EnableGoogleAnalyticsDebugMode"))
199 {
200 GoogleAnalyticsDebugMode = ", {'debug_mode': true}";
201 }
202203 <script async src="https://www.googletagmanager.com/gtag/js?id=@googleAnalyticsMeasurementID"></script>
204 <script>
205 gtag('js', new Date());
206 gtag('config', '@googleAnalyticsMeasurementID'@GoogleAnalyticsDebugMode);
207 </script>
208 }
209210 @if (!string.IsNullOrWhiteSpace(customHeaderInclude))
211 {
212 @RenderPartial($"Components/Custom/{customHeaderInclude}")
213 }
214 </head>
215216 <body class="brand @(masterTheme)">
217218 @* Google tag manager *@
219 @if (!string.IsNullOrWhiteSpace(googleTagManagerID) && allowTracking)
220 {
221 <noscript>
222 <iframe src="https://www.googletagmanager.com/ns.html?id=@(googleTagManagerID)"
223 height="0" width="0" style="display:none;visibility:hidden"></iframe>
224 </noscript>
225 }
226227 <div data-intersect></div>
228229 <main id="content" @(schemaOrgType)>
230 @inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.PageViewModel>
231 @using System
232 @using Dynamicweb.Ecommerce.ProductCatalog
233234 @{
235 string theme = "";
236 string gridContent = "";
237238 if (Model.PropertyItem != null)
239 {
240 theme = !string.IsNullOrWhiteSpace(Model.PropertyItem.GetRawValueString("Theme")) ? " theme " + Model.PropertyItem.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : "";
241 }
242243 if (Model.Item != null)
244 {
245 gridContent = Model.Grid("Grid", "Grid", "default:true;sort:1", "Page");
246 }
247248 bool doNotRenderPage = false;
249250 //Check if we are on the poduct detail page, and if there is data to render
251 ProductViewModel product = new ProductViewModel();
252 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails"))
253 {
254 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"];
255 if (string.IsNullOrEmpty(product.Id))
256 {
257 doNotRenderPage = true;
258 }
259 }
260261 //Render the page
262 if (!doNotRenderPage)
263 {
264 string itemIdentifier = Model?.Item?.SystemName != null ? "item_" + Model.Item.SystemName.ToLower() : "item_Swift_Page";
265266 if (theme != "")
267 {
268 <div class="@theme item_@itemIdentifier">
269 @gridContent
270 </div>
271 }
272 else
273 {
274 <div class="item_@itemIdentifier">
275 @gridContent
276 </div>
277 }
278 }
279 else
280 {
281 <div class="container">
282 <div class="alert alert-info" role="alert">@Translate("Sorry. There is nothing to view here")</div>
283 </div>
284 }
285286 if (!Model.IsCurrentUserAllowed)
287 {
288 int signInPage = GetPageIdByNavigationTag("SignInPage");
289 int dashboardPage = GetPageIdByNavigationTag("MyAccountDashboardPage");
290291 if (!Pageview.IsVisualEditorMode)
292 {
293 if (signInPage != 0)
294 {
295 if (signInPage != Model.ID)
296 {
297 Dynamicweb.Context.Current.Response.Redirect("/Default.aspx?ID=" + signInPage);
298 }
299 else
300 {
301 if (dashboardPage != 0)
302 {
303 Dynamicweb.Context.Current.Response.Redirect("/Default.aspx?ID=" + dashboardPage);
304 }
305 else
306 {
307 Dynamicweb.Context.Current.Response.Redirect("/");
308 }
309 }
310 }
311 else
312 {
313 <div class="alert alert-dark m-0" role="alert">
314 <span>@Translate("You do not have access to this page")</span>
315 </div>
316 }
317 }
318 else
319 {
320 <div class="alert alert-dark m-0" role="alert">
321 <span>@Translate("To work on this page, you must be signed in, in the frontend")</span>
322 </div>
323 }
324 }
325 }
326327 </main>
328329 @* Render any offcanvas menu here *@
330 @RenderSnippet("offcanvas")
331 </body>
332333 </html>
334