Error executing template "Designs/Swift/_parsed/Swift_Page.parsed.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Dynamicweb.Frontend.ContentViewModelFactory.CreateItemViewModel(Item item, Page page, Paragraph paragraph)
   at Dynamicweb.Frontend.ContentViewModelFactory.CreatePageViewModel(PageView pageView)
   at Dynamicweb.Frontend.PageView.SetPageTemplateValues()
   at Dynamicweb.Frontend.PageView.Output()
   at CompiledRazorTemplates.Dynamic.RazorEngine_2affaf67ea404f5c8668eac7806ca1bb.Execute() in D:\dynamicweb.net\Solutions\Dynamicweb\dynamicwebdemo.dwsales.dynamicweb-cms.com\files\Templates\Designs\Swift\_parsed\Swift_Page.parsed.cshtml:line 55
   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 System.Web 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 responsiveHeaderClassDesktop = string.Empty; 13 string responsiveHeaderClassMobile = string.Empty; 14 if (renderAsResponsive) 15 { 16 responsiveHeaderClassDesktop = " d-none d-xl-block"; 17 responsiveHeaderClassMobile = " d-block d-xl-none"; 18 19 } 20 21 var brandingPageId = Model.Area.Item.GetLink("BrandingPage") != null ? Model.Area.Item.GetLink("BrandingPage").PageId : 0; 22 var themePageId = Model.Area.Item.GetLink("ThemesPage") != null ? Model.Area.Item.GetLink("ThemesPage").PageId : 0; 23 string customHeaderInclude = Model.Area.Item.GetFile("CustomHeaderInclude") != null ? Model.Area.Item.GetFile("CustomHeaderInclude").Name : string.Empty; 24 25 var brandingPage = Dynamicweb.Services.Pages?.GetPage(brandingPageId) ?? null; 26 var themesParagraphLastChanged = Services.Paragraphs.GetParagraphsByPageId(themePageId).OrderByDescending(p => p.Audit.LastModifiedAt).FirstOrDefault(); 27 28 var cssLastModified = brandingPage.Audit.LastModifiedAt > themesParagraphLastChanged.Audit.LastModifiedAt ? brandingPage.Audit.LastModifiedAt : themesParagraphLastChanged.Audit.LastModifiedAt; 29 var cssThemeAndBrandingStyleFileInfo = new System.IO.FileInfo(Dynamicweb.Core.SystemInformation.MapPath($"~/Files/Templates/Designs/Swift/_parsed/Swift_css/Swift_styles_{Model.Area.ID}.min.css")); 30 31 // Schema.org details for PDP 32 string productId = !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString.Get("ProductID")) ? Dynamicweb.Context.Current.Request.QueryString.Get("ProductID") : ""; 33 bool isProductDetailsPage = !string.IsNullOrEmpty(productId); 34 string productDetailPageSchemaOrg = isProductDetailsPage ? "itemscope=\"\" itemtype=\"https://schema.org/Product\"" : ""; 35 36 if (!cssThemeAndBrandingStyleFileInfo.Exists || cssThemeAndBrandingStyleFileInfo.LastWriteTime < brandingPage.Audit.LastModifiedAt) 37 { 38 //Branding page has been saved or the file is missing. Rewrite the file to disc. 39 if (brandingPageId > 0) 40 { 41 var brandingPageview = Dynamicweb.Frontend.PageView.GetPageviewByPageID(brandingPageId); 42 brandingPageview.Redirect = false; 43 brandingPageview.Output(); 44 } 45 } 46 47 48 if (!cssThemeAndBrandingStyleFileInfo.Exists || cssThemeAndBrandingStyleFileInfo.LastWriteTime < themesParagraphLastChanged.Audit.LastModifiedAt) 49 { 50 //Branding page has been saved or the file is missing. Rewrite the file to disc. 51 if (themePageId > 0) 52 { 53 var themePageview = Dynamicweb.Frontend.PageView.GetPageviewByPageID(themePageId); 54 themePageview.Redirect = false; 55 themePageview.Output(); 56 } 57 } 58 59 var cssStyleFileInfo = new System.IO.FileInfo(Dynamicweb.Core.SystemInformation.MapPath("~/Files/Templates/Designs/Swift/Assets/css/styles.css")); 60 var jsFileInfo = new System.IO.FileInfo(Dynamicweb.Core.SystemInformation.MapPath("~/Files/Templates/Designs/Swift/Assets/js/scripts.js")); 61 62 string masterTheme = !string.IsNullOrWhiteSpace(Model.Area.Item.GetRawValueString("Theme")) ? " theme " + Model.Area.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 63 64 string headerCssClass = "sticky-top"; 65 bool movePageBehind = false; 66 string scrollInitScript = "swift.Scroll.init(); AOS.init({offset: 240, duration: 600, delay: 100}); disable: window.matchMedia('(prefers-reduced-motion: reduce)');"; 67 if (Pageview.Page.PropertyItem != null) 68 { 69 headerCssClass = Pageview.Page.PropertyItem["MoveThisPageBehindTheHeader"] != null ? Pageview.Page.PropertyItem["MoveThisPageBehindTheHeader"].ToString() : "sticky-top"; 70 movePageBehind = headerCssClass == "fixed-top" && !Pageview.IsVisualEditorMode ? true : false; 71 } 72 headerCssClass = headerCssClass == "" ? "sticky-top" : headerCssClass; 73 headerCssClass = Pageview.IsVisualEditorMode ? "" : headerCssClass; 74 75 string googleAnalyticsTrackingID = Model.Area.Item.GetString("GoogleAnalyticsTrackingID"); 76 bool allowCookies = CookieManager.GetCookieOptInLevel() == 0 || !CookieManager.CookieOptInLevelExists ? false : true; 77 78 Dynamicweb.Context.Current.Response.AddHeader("link", $"</Files/Templates/Designs/Swift/Assets/css/styles.css?{cssStyleFileInfo.LastWriteTime.Ticks}>; rel=preload; as=style;"); 79 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;"); 80 Dynamicweb.Context.Current.Response.AddHeader("link", $"</Files/Templates/Designs/Swift/Assets/js/aos.js?{jsFileInfo.LastWriteTime.Ticks}; rel=preload; as=script;"); 81 Dynamicweb.Context.Current.Response.AddHeader("link", $"</Files/Templates/Designs/Swift/Assets/js/scripts.js?{jsFileInfo.LastWriteTime.Ticks}; rel=preload; as=script;"); 82 //Dynamicweb.Context.Current.Response.Flush(); //This sends the headers where we are now in the rendering making the TTFB faster 83 84 SetMetaTags(); 85 86 List<Dynamicweb.Content.Page> languages = new List<Dynamicweb.Content.Page>(); 87 88 if (Pageview.Area.IsMaster) { 89 languages.Add(Pageview.Page); 90 if (Pageview.Page.Languages != null) { 91 foreach (var language in Pageview.Page.Languages) { 92 languages.Add(language); 93 } 94 } 95 } else { 96 languages.Add(Pageview.Page.MasterPage); 97 if (Pageview.Page.MasterPage != null) { 98 if (Pageview.Page.MasterPage.Languages != null) { 99 foreach (var language in Pageview.Page.MasterPage.Languages) { 100 languages.Add(language); 101 } 102 } 103 } 104 } 105 106 string siteLanguage = Pageview.Area.CultureInfo.Name; 107 Uri url = Dynamicweb.Context.Current.Request.Url; 108 string hostName = url.Host; // domain.com/da-dk or domain.com/en-us 109 110 var ecomCountries = Dynamicweb.Ecommerce.Services.Countries.GetCountries(); 111 var ecomCurrencies = Dynamicweb.Ecommerce.Services.Currencies.GetAllCurrencies(); 112 } 113 <!doctype html> 114 <html lang="@Pageview.Area.CultureInfo.TwoLetterISOLanguageName"> 115 <head> 116 <!-- @swiftVersion --> 117 @* Required meta tags *@ 118 <meta charset="utf-8"> 119 <meta name="viewport" content="height=device-height, width=device-width, initial-scale=1.0"> 120 <link rel="preconnect" href="https://fonts.gstatic.com" /> 121 122 <link rel="shortcut icon" href="~/Files/Templates/Designs/Swift/Assets/Images/favicon.png"> 123 <link rel="apple-touch-icon" href="~/Files/Templates/Designs/Swift/Assets/Images/logo_transparent.png"> 124 125 @Model.MetaTags 126 127 @{ 128 @* Languages meta data *@ 129 foreach (var language in languages) 130 { 131 if (language != null) { 132 if (!string.IsNullOrEmpty(language.Area.DomainLock)) 133 { 134 hostName = language.Area.DomainLock; //dk.domain.com or dk-domain.dk 135 } 136 string friendlyUrl = Dynamicweb.Frontend.SearchEngineFriendlyURLs.GetFriendlyUrl(language.ID); 137 string href = $"{url.Scheme}://{hostName}{friendlyUrl}"; 138 139 <link rel="alternate" hreflang="@language.Area.CultureInfo.Name.ToLower()" href="@href" /> 140 } 141 } 142 } 143 144 <title>@Model.Title</title> 145 @* Bootstrap + Swift stylesheet *@ 146 <link href="~/Files/Templates/Designs/Swift/Assets/css/styles.css?@cssStyleFileInfo.LastWriteTime.Ticks" rel="stylesheet" media="all" type="text/css"> 147 @* Branding and Themes min stylesheet *@ 148 <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"> 149 <script src="~/Files/Templates/Designs/Swift/Assets/js/aos.js?@jsFileInfo.LastWriteTime.Ticks" defer></script> 150 <script src="~/Files/Templates/Designs/Swift/Assets/js/scripts.js?@jsFileInfo.LastWriteTime.Ticks" defer></script> 151 152 @* Global site tag (gtag.js) - Google Analytics *@ 153 @if (!string.IsNullOrWhiteSpace(googleAnalyticsTrackingID) && allowCookies) 154 { 155 <script src="https://www.googletagmanager.com/gtag/js?id=@googleAnalyticsTrackingID" async></script> 156 <script>@googleAnalyticsTrackingID</script> 157 } 158 159 @if (!string.IsNullOrWhiteSpace(customHeaderInclude)) { 160 @RenderPartial($"Components/Custom/{customHeaderInclude}") 161 } 162 </head> 163 <body class="brand @(masterTheme)" id="page@(Model.ID)" onload="@scrollInitScript"> 164 @if (renderAsResponsive || !renderMobile) 165 { 166 <header class="page-header @headerCssClass top-0@(responsiveHeaderClassDesktop)" id="page-header-desktop"> 167 @if (@Model.Area.Item.GetLink("HeaderDesktop") != null) 168 { 169 @RenderGrid(@Model.Area.Item.GetLink("HeaderDesktop").PageId) 170 } 171 </header> 172 } 173 174 @if ((renderAsResponsive || renderMobile)) 175 { 176 <header class="page-header @headerCssClass top-0@(responsiveHeaderClassMobile)" id="page-header-mobile"> 177 @if (@Model.Area.Item.GetLink("HeaderMobile") != null) 178 { 179 @RenderGrid(@Model.Area.Item.GetLink("HeaderMobile").PageId) 180 } 181 </header> 182 } 183 184 <main id="content" @productDetailPageSchemaOrg> 185 @inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.PageViewModel> 186 @using System 187 @using Dynamicweb.Ecommerce.ProductCatalog 188 189 @{ 190 string theme = ""; 191 string gridContent = ""; 192 193 if (Model.PropertyItem != null) 194 { 195 theme = !string.IsNullOrWhiteSpace(Model.PropertyItem.GetRawValueString("Theme")) ? " theme " + Model.PropertyItem.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 196 } 197 198 if (Model.Item != null) 199 { 200 gridContent = Model.Grid("Grid", "Grid", "default:true;sort:1", "Page"); 201 } 202 203 bool doNotRenderPage = false; 204 205 //Check if we are on the poduct detail page, and if there is data to render 206 ProductViewModel product = new ProductViewModel(); 207 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 208 { 209 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 210 if (string.IsNullOrEmpty(product.Id)) { 211 doNotRenderPage = true; 212 } 213 } 214 215 //Render the page 216 if (!doNotRenderPage) { 217 if (theme != "") 218 { 219 <div class="@theme"> 220 @gridContent 221 </div> 222 } 223 else 224 { 225 @gridContent 226 } 227 } else { 228 <div class="container"> 229 <div class="alert alert-info" role="alert">@Translate("Sorry. There is nothing to view here")</div> 230 </div> 231 } 232 233 if (!Model.IsCurrentUserAllowed) 234 { 235 int signInPage = GetPageIdByNavigationTag("SignInPage"); 236 int dashboardPage = GetPageIdByNavigationTag("MyAccountDashboardPage"); 237 238 if (!Pageview.IsVisualEditorMode) 239 { 240 if (signInPage != 0) 241 { 242 if (signInPage != Model.ID) { 243 Dynamicweb.Context.Current.Response.Redirect("/Default.aspx?ID=" + signInPage); 244 } else { 245 if (dashboardPage != 0) { 246 Dynamicweb.Context.Current.Response.Redirect("/Default.aspx?ID=" + dashboardPage); 247 } else { 248 Dynamicweb.Context.Current.Response.Redirect("/"); 249 } 250 } 251 } 252 else 253 { 254 <div class="alert alert-dark m-0" role="alert"> 255 <span>@Translate("You do not have access to this page")</span> 256 </div> 257 } 258 } 259 else 260 { 261 <div class="alert alert-dark m-0" role="alert"> 262 <span>@Translate("To work on this page, you must be signed in, in the frontend")</span> 263 </div> 264 } 265 } 266 } 267 268 </main> 269 270 @if (renderAsResponsive || !renderMobile) 271 { 272 <footer class="page-footer d-none d-lg-block" id="page-footer-desktop"> 273 @if (@Model.Area.Item.GetLink("FooterDesktop") != null) 274 { 275 @RenderGrid(@Model.Area.Item.GetLink("FooterDesktop").PageId) 276 } 277 </footer> 278 } 279 280 @if (renderAsResponsive || renderMobile) 281 { 282 <footer class="page-footer d-block d-lg-none" id="page-footer-mobile"> 283 @if (@Model.Area.Item.GetLink("FooterMobile") != null) 284 { 285 @RenderGrid(@Model.Area.Item.GetLink("FooterMobile").PageId) 286 } 287 </footer> 288 } 289 290 @* Render any offcanvas menu here *@ 291 @RenderSnippet("offcanvas") 292 293 @* Language selector modal *@ 294 @if (languages.Count > 1 || ecomCountries.Count > 1 || ecomCurrencies.Count() > 1) 295 { 296 <div class="modal fade" id="PreferencesModal" tabindex="-1" aria-hidden="true"> 297 <div class="modal-dialog modal-dialog-centered modal-sm" id="PreferencesModalContent"> 298 @* The content here comes from an external request *@ 299 </div> 300 </div> 301 } 302 303 @* Offcanvas for dynamic content *@ 304 <div class="offcanvas offcanvas-end theme light" tabindex="-1" id="DynamicOffcanvas" style="width: 30rem"> 305 @* The content here comes from an external request *@ 306 </div> 307 </body> 308 </html> 309 @functions { 310 311 void SetMetaTags() 312 { 313 //Verification Tokens 314 string siteVerificationGoogle = Model.Area.Item.GetString("Google_Site_Verification") != null ? Model.Area.Item.GetString("Google_Site_Verification") : ""; 315 //string siteVerificationYandex = Model.Area.Item.GetString("Yandex_Verification") != null ? Model.Area.Item.GetString("Yandex_Verification") : ""; 316 //string siteVerificationMS = Model.Area.Item.GetString("Msvalidate_01") != null ? Model.Area.Item.GetString("Msvalidate_01") : ""; 317 //string siteVerificationAlexa = Model.Area.Item.GetString("AlexaVerifyID") != null ? Model.Area.Item.GetString("AlexaVerifyID") : ""; 318 //string siteVerificationPinterest = Model.Area.Item.GetString("P_domain_verify") != null ? Model.Area.Item.GetString("P_domain_verify") : ""; 319 //string siteVerificationNorton = Model.Area.Item.GetString("Norton_safeweb_site_verification") != null ? Model.Area.Item.GetString("Norton_safeweb_site_verification") : ""; 320 321 //Generic Site Values 322 string openGraphFacebookAppID = Model.Area.Item.GetString("Fb_app_id") != null ? Model.Area.Item.GetString("Fb_app_id") : ""; 323 string openGraphType = Model.Area.Item.GetString("Open_Graph_Type") != null ? Model.Area.Item.GetString("Open_Graph_Type") : ""; 324 string openGraphSiteName = Model.Area.Item.GetString("Open_Graph_Site_Name") != null ? Model.Area.Item.GetString("Open_Graph_Site_Name") : ""; 325 326 string twitterCardSite = Model.Area.Item.GetString("Twitter_Site") != null ? Model.Area.Item.GetString("Twitter_Site") : ""; 327 328 //Page specific values 329 string openGraphSiteTitle = Model.Area.Item.GetString("Open_Graph_Title") != null ? Model.Area.Item.GetString("Open_Graph_Title") : ""; 330 FileViewModel openGraphImage = Model.Area.Item.GetFile("Open_Graph_Image"); 331 string openGraphImageALT = Model.Area.Item.GetString("Open_Graph_Image_ALT") != null ? Model.Area.Item.GetString("Open_Graph_Image_ALT") : ""; 332 string openGraphDescription = Model.Area.Item.GetString("Open_Graph_Description") != null ? Model.Area.Item.GetString("Open_Graph_Description") : ""; 333 334 string twitterCardURL = Model.Area.Item.GetString("Twitter_URL") != null ? Model.Area.Item.GetString("Twitter_URL") : ""; 335 string twitterCardTitle = Model.Area.Item.GetString("Twitter_Title") != null ? Model.Area.Item.GetString("Twitter_Title") : ""; 336 string twitterCardDescription = Model.Area.Item.GetString("Twitter_Description") != null ? Model.Area.Item.GetString("Twitter_Description") : ""; 337 FileViewModel twitterCardImage = Model.Area.Item.GetFile("Twitter_Image"); 338 string twitterCardImageALT = Model.Area.Item.GetString("Twitter_Image_ALT") != null ? Model.Area.Item.GetString("Twitter_Image_ALT") : ""; 339 340 if (!string.IsNullOrEmpty(siteVerificationGoogle)) 341 { 342 Pageview.Meta.AddTag("google-site-verification", siteVerificationGoogle); 343 } 344 345 if (!string.IsNullOrEmpty(openGraphFacebookAppID)) 346 { 347 Pageview.Meta.AddTag("fb:app_id", openGraphFacebookAppID); 348 } 349 350 if (!string.IsNullOrEmpty(openGraphType)) 351 { 352 Pageview.Meta.AddTag("og:type", openGraphType); 353 } 354 355 if (!string.IsNullOrEmpty(openGraphSiteName)) 356 { 357 Pageview.Meta.AddTag("og:site_name", openGraphSiteName); 358 } 359 360 if (!string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString["GroupID"]) && !string.IsNullOrEmpty(Dynamicweb.Context.Current.Request.QueryString["ProductID"])) 361 { 362 if (!string.IsNullOrEmpty(Model.Title)) 363 { 364 Pageview.Meta.AddTag("og:title", Model.Title); 365 } 366 else 367 { 368 Pageview.Meta.AddTag("og:title", openGraphSiteTitle); 369 } 370 if (!string.IsNullOrEmpty(Model.Description)) 371 { 372 Pageview.Meta.AddTag("og:description", Model.Description); 373 } 374 else 375 { 376 Pageview.Meta.AddTag("og:description", openGraphDescription); 377 } 378 } 379 380 if (openGraphImage != null) 381 { 382 Pageview.Meta.AddTag("og:image", openGraphImage.Path); 383 } 384 385 if (!string.IsNullOrEmpty(openGraphImageALT)) 386 { 387 Pageview.Meta.AddTag("og:image:alt", openGraphImageALT); 388 } 389 390 if (!string.IsNullOrEmpty(twitterCardSite)) 391 { 392 Pageview.Meta.AddTag("twitter:site", twitterCardSite); 393 } 394 395 if (!string.IsNullOrEmpty(twitterCardURL)) 396 { 397 Pageview.Meta.AddTag("twitter:url", twitterCardURL); 398 } 399 400 if (!string.IsNullOrEmpty(twitterCardTitle)) 401 { 402 Pageview.Meta.AddTag("twitter:title", twitterCardTitle); 403 } 404 405 if (!string.IsNullOrEmpty(twitterCardDescription)) 406 { 407 Pageview.Meta.AddTag("twitter:description", twitterCardDescription); 408 } 409 410 if (twitterCardImage != null) 411 { 412 Pageview.Meta.AddTag("twitter:image", twitterCardImage.Path); 413 } 414 415 if (!string.IsNullOrEmpty(twitterCardImageALT)) 416 { 417 Pageview.Meta.AddTag("twitter:image:alt", twitterCardImageALT); 418 } 419 } 420 } 421