Error executing template "Designs/Designa/_parsed/Dw_Page.parsed.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at Designa.Website.CustomModules.Helpers.TemplateHelper.GetCanonical(HttpRequest req, Int32 pageView) in C:\azp\agent\_work\13\s\Designa.Website\CustomModules\Helpers\TemplateHelper.cs:line 178
   at CompiledRazorTemplates.Dynamic.RazorEngine_6f124fd2919044e38c01ff05a96ff5c7.Execute() in E:\WEB\designa.dk\Files\Templates\Designs\Designa\_parsed\Dw_Page.parsed.cshtml:line 17
   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.RazorTemplateBase<Dynamicweb.Rendering.RazorTemplateModel<Dynamicweb.Rendering.Template>> 2 @using Designa.Website.CustomModules.ViewModels 3 @using Designa.Website.CustomModules 4 @using Designa.Website.CustomModules.Helpers 5 @using Dynamicweb.Frontend 6 @using Dynamicweb.Rendering 7 8 @{ 9 var httpRequest = System.Web.HttpContext.Current.Request; 10 var scheme = httpRequest.Url.Scheme; 11 var host = httpRequest.Url.Host; 12 var pageTitle = PageView.Current().Page.MetaTitle; 13 var metaDescription = PageView.Current().Page.Description; 14 var frontPageId = Pageview.GetPageviewModel().Area.FirstPage.ID.ToString(); 15 var currentPageId = PageView.Current().Page.ID.ToString(); 16 var currentUrl = SearchEngineFriendlyURLs.GetFriendlyUrl(currentPageId); 17 var canonicalUrl = TemplateHelper.GetCanonical(httpRequest, Pageview.ID); 18 var getNoIndexNoFollow = TemplateHelper.GetNoIndexNoFollow(httpRequest, Pageview.ID); 19 var pathToStyles = Constants.DistPath + "/css/master.min.css"; 20 var pathToJsManifest = Constants.DistPath + "/scripts/manifest.bundle.js"; 21 var pathToJsVendor = Constants.DistPath + "/scripts/vendor.bundle.js"; 22 var pathToJsApp = Constants.DistPath + "/scripts/app.bundle.js"; 23 var pathToCustomScripts = Constants.ProjectPath + "/Scripts/custom.js"; 24 var pathToLogo = Constants.DistPath + "/images/logo.svg"; 25 var productId = System.Web.HttpContext.Current.Request.QueryString["productid"]; 26 var gtm = Dynamicweb.Frontend.PageView.Current().AreaSettings.GetString("GTM_ID"); 27 28 } 29 <!DOCTYPE html> 30 <html lang="@Pageview.Area.CultureInfo.TwoLetterISOLanguageName" xmlns:xlink="http://www.w3.org/1999/xlink"> 31 <head> 32 <meta charset="utf-8"> 33 <meta name="viewport" content="width=device-width, initial-scale=1"> 34 <link rel="preconnect" href="https://fonts.gstatic.com"> 35 <link rel="preconnect" as="style" href="https://fonts.googleapis.com/css2?family=Abril+Fatface&family=Prata&family=Spartan:wght@500;700&display=swap"> 36 <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Abril+Fatface&family=Prata&family=Spartan:wght@500;700&display=swap" media="print" onload="this.media = 'all'"> 37 <noscript> 38 <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Abril+Fatface&family=Prata&family=Spartan:wght@500;700&display=swap"> 39 </noscript> 40 41 @if (host.Contains("local") || host.Contains("stagingsite") || host.Contains("ditnyewebsite")) 42 { 43 <meta name="robots" content="noindex, nofollow"> 44 } 45 else 46 { 47 if(!string.IsNullOrEmpty(getNoIndexNoFollow)) 48 { 49 @getNoIndexNoFollow 50 } 51 } 52 53 <title>@GetValue("Title")</title> 54 55 @if (string.IsNullOrEmpty(canonicalUrl) && currentPageId == frontPageId) // Frontpage 56 { 57 <link rel="canonical" href="/"> 58 } 59 else if (!string.IsNullOrEmpty(canonicalUrl)) 60 { 61 <link rel="canonical" href="@canonicalUrl"> 62 } 63 else 64 { 65 <link rel="canonical" href="@PageView.Current().Page.MetaCanonical"> 66 } 67 68 @if (!string.IsNullOrEmpty(metaDescription)) 69 { 70 <meta name="description" content="@metaDescription"> 71 } 72 <meta name="p:domain_verify" content="b2eeee1f0a8002e1df4ad3d202252517"> 73 <meta property="og:image" content="@TemplateHelper.GetAbsoluteUrl(pathToLogo)"> 74 <link media="all" href="@TemplateHelper.GetRevisionNumber(pathToStyles)" rel="stylesheet"> 75 <link rel="apple-touch-icon" sizes="180x180" href="/favicon/apple-touch-icon.png"> 76 <link rel="icon" type="image/png" sizes="32x32" href="/favicon/favicon-32x32.png"> 77 <link rel="icon" type="image/png" sizes="16x16" href="/favicon/favicon-16x16.png"> 78 <script src="@TemplateHelper.GetRevisionNumber(pathToCustomScripts)"></script> 79 80 @if (!host.Contains("local") && !String.IsNullOrEmpty(gtm)) 81 { 82 83 <!-- Google Tag Manager --> 84 <script> 85 (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': 86 new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], 87 j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 88 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); 89 })(window,document,'script','dataLayer','@gtm');</script> 90 <!-- End Google Tag Manager --> 91 } 92 <!-- TrustBox script --> 93 <script type="text/javascript" src="//widget.trustpilot.com/bootstrap/v5/tp.widget.bootstrap.min.js" async=""></script> 94 <!-- End TrustBox script --> 95 </head> 96 <body class=""> 97 98 @if (!host.Contains("local") && !String.IsNullOrEmpty(gtm)) 99 { 100 <!-- Google Tag Manager (noscript) --> 101 <noscript> 102 <iframe src="https://www.googletagmanager.com/ns.html?id=@gtm" height="0" width="0" style="display:none;visibility:hidden"></iframe> 103 </noscript> 104 <!-- End Google Tag Manager (noscript) --> 105 } 106 107 @TemplateHelper.RenderPartial("Master/Partials/GlobalHeader.cshtml", new GlobalHeaderViewModel(Pageview)) 108 @TemplateHelper.RenderPartial("Master/Partials/Navigation.cshtml") 109 @*@inherits Dynamicweb.Rendering.RazorTemplateBase<Dynamicweb.Rendering.RazorTemplateModel<Dynamicweb.Rendering.Template>> 110 @using Designa.Website.CustomModules 111 @using Designa.Website.CustomModules.Helpers 112 @using Designa.Website.CustomModules.Helpers.Models 113 @using Dynamicweb 114 @using Dynamicweb.Content 115 @using Dynamicweb.Ecommerce.Frontend 116 @using Dynamicweb.Frontend 117 118 @{ 119 var Button1Text = Pageview.AreaSettings.GetString("NavigationButton1Text"); 120 var Button1Link = Pageview.AreaSettings.GetString("NavigationButton1Link"); 121 122 var Button2Text = Pageview.AreaSettings.GetString("NavigationButton2Text"); 123 var Button2Link = Pageview.AreaSettings.GetString("NavigationButton2Link"); 124 125 var Button3Text = Pageview.AreaSettings.GetString("NavigationButton3Text"); 126 var Button3Link = Pageview.AreaSettings.GetString("NavigationButton3Link"); 127 128 var ctaImages = new List<CallToActionImage>(); 129 var ctaImageLinks = TemplateHelper.GetItemRelationListWithId(Pageview, "CTAImageLinks", "CTAImageLink"); 130 131 foreach (var ctaImage in ctaImageLinks) 132 { 133 ctaImages.Add(new CallToActionImage(ctaImage)); 134 } 135 136 137 var textCloseNavigation = Translate("NavigationOverlay.CloseNavigation", "Luk navigationen"); 138 } 139 140 <div class="navigation-overlay navigation-overlay--closed" id="js-navigation-overlay"> 141 <div class="container navigation-overlay__container"> 142 <div class="row navigation-overlay__row-navigation"> 143 <div class="col-xs-7 col-sm-9 col-lg-8 col-lg-offset-1 navigation-overlay__col" id="js-navigation-overlay__navigation"> 144 145 <nav class="navigation-desktop" v-bind:aria-hidden="navigationLayout === 'mobile'"> 146 <ul class="navigation-desktop__list"> 147 @RenderNavigationListItem("desktop1") 148 149 </ul> 150 151 <ul class="navigation-desktop__list-level-2"> 152 @RenderNavigationListItem("desktop2") 153 154 </ul> 155 </nav> 156 157 <nav class="navigation-mobile" v-bind:aria-hidden="navigationLayout === 'desktop'"> 158 <ul class="navigation-mobile__list"> 159 @RenderNavigationListItem("mobile") 160 </ul> 161 </nav> 162 </div> 163 <div class="col-xs-5 col-sm-3 col-lg-2 navigation-overlay__col"> 164 @if (!String.IsNullOrWhiteSpace(Button1Text) && !String.IsNullOrWhiteSpace(Button1Link)) 165 { 166 <a href="@Button1Link" property="url" class="button button--color-2 button--full-width">@Button1Text</a> 167 } 168 @if (!String.IsNullOrWhiteSpace(Button2Text) && !String.IsNullOrWhiteSpace(Button2Link)) 169 { 170 <a href="@Button2Link" property="url" class="button button--color-1-mid button--full-width">@Button2Text</a> 171 } 172 @if (!String.IsNullOrWhiteSpace(Button3Text) && !String.IsNullOrWhiteSpace(Button3Link)) 173 { 174 <a href="@Button3Link" property="url" class="button button--ghost-black button--full-width">@Button3Text</a> 175 } 176 </div> 177 178 </div> 179 <div class="row"> 180 <div class="col-xs-12"> 181 <ul class="highlights"> 182 @foreach (var ctaImage in ctaImages) { 183 <li class="highlights__item"> 184 <img class="lazyload lazyload-bg image lazyload-measure lazyload-bg " width="0" height="0" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" alt="@ctaImage.ImageAltText" property="contentUrl" data-src="@ctaImage.ImageLink" data-query-obj='{"mode":"crop"}'> 185 <noscript v-if="false"> 186 <img src="@ctaImage.ImageLink?mode=crop&width=" alt="@ctaImage.ImageAltText"> 187 </noscript> 188 189 <a href="@ctaImage.PageLink" class="h3 highlights__link">@ctaImage.Name</a> 190 </li> 191 } 192 </ul> 193 </div> 194 </div> 195 196 </div> 197 198 <button type="button" class="close-overlay-button" @@click="close" title="@textCloseNavigation"> 199 <span class="visually-hidden">@textCloseNavigation</span> 200 </button> 201 </div> 202 203 @helper RenderNavigationListItem(string navigationType) 204 { 205 var rootNodes = Services.Pages.GetAreaNavigationTree(Pageview.AreaID).RootNodes.Where(x => x.IsPublished); 206 var currentContentItemPathIds = DWHelper.GetContentTreePageIds(Pageview.Page); 207 208 if(navigationType == "mobile") { 209 rootNodes = Services.Pages.GetAreaNavigationTree(Pageview.AreaID).RootNodes.Where(x => x.IsPublished); 210 } 211 212 int listCount = 0; 213 foreach (var node in rootNodes) 214 { 215 //Check børnebørn(e)børn osv 216 var children = node.Children.Where(x => x.IsPublished).OrderBy(x => x.Sort).ToList(); 217 bool hasChildren = children.Count > 0; 218 var dataHasSubnavigation = hasChildren ? "data-has-subnavigation=\"true\"" : ""; 219 var pageIsActive = currentContentItemPathIds.FirstOrDefault(x => x == node.ID) != 0; 220 var dataLevel1Active = pageIsActive ? "data-level-1-active=\"true\"" : ""; 221 222 var itemLevel = 1; 223 var activeVueClass = ""; 224 var vif=""; 225 var baseClass = "navigation-desktop"; 226 227 if(navigationType == "desktop2") { 228 itemLevel = 2; 229 vif="v-if=\"activeItemLevel1 === "+listCount+"\""; 230 } 231 232 if(navigationType == "mobile") { 233 baseClass = "navigation-mobile"; 234 } 235 236 if(navigationType == "desktop1" || navigationType == "mobile"){ 237 activeVueClass = "v-bind:class=\"{'"+baseClass+"__item-level-1--active': activeItemLevel1 === "+listCount+" }\""; 238 } 239 240 <li class="@(baseClass)__item-level-@itemLevel" @datahassubnavigation="" @datalevel1active="" @vif="" @activevueclass="" data-level-1-id="@listCount"> 241 242 @if(navigationType == "desktop1" || navigationType == "mobile"){ 243 if (hasChildren) 244 { 245 <button type="button" class="h5 @(baseClass)__link-level-1" @@click="show(@listCount)">@node.Title 246 <span class="navigation-overlay__arrow"> 247 <svg class="svg-icon navigation-overlay__svg" aria-hidden="true"> 248 <use xlink:href="/dist/icons/icons.svg#arrow-right"></use> 249 </svg> 250 </span> 251 </button> 252 }else{ 253 <a href="@(SearchEngineFriendlyURLs.GetFriendlyUrl(node.ID))" class="h5 @(baseClass)__link-level-1">@node.Title 254 <span class="navigation-overlay__arrow"> 255 <svg class="svg-icon navigation-overlay__svg" aria-hidden="true"> 256 <use xlink:href="/dist/icons/icons.svg#arrow-right"></use> 257 </svg> 258 </span> 259 </a> 260 } 261 } 262 263 @if(navigationType == "desktop2" || navigationType == "mobile"){ 264 if (hasChildren) 265 { 266 <ul class="@(baseClass)__sub-list"> 267 <li class="@(baseClass)__item-level-2"> 268 <a href="@SearchEngineFriendlyURLs.GetFriendlyUrl(node.ID)" class="@(baseClass)__link-level-2">@node.Title</a> 269 </li> 270 @foreach (var grandChild in children) 271 { 272 var pageLeve2Active = currentContentItemPathIds.FirstOrDefault(x => x == grandChild.ID) != 0; 273 var classLevel2Active = pageLeve2Active ? "navigation-desktop__item-level-2--active" : ""; 274 var classLevel2ActiveMobile = pageLeve2Active ? "--active" : ""; 275 276 <li class="@(baseClass)__item-level-2@(classLevel2ActiveMobile) @classLevel2Active"> 277 <a href="@SearchEngineFriendlyURLs.GetFriendlyUrl(grandChild.ID)" class="@(baseClass)__link-level-2">@grandChild.Title</a> 278 </li> 279 } 280 </ul> 281 } 282 } 283 284 </li> 285 listCount++; 286 } 287 } 288 *@ 289 @TemplateHelper.RenderPartial("Master/Partials/Breadcrumb.cshtml") 290 @inherits Dynamicweb.Rendering.RazorTemplateBase<Dynamicweb.Rendering.RazorTemplateModel<Dynamicweb.Rendering.Template>> 291 292 293 294 <div id="content">@GetValue("DwContent(content)")</div> 295 296 @TemplateHelper.RenderPartial("Master/Partials/SearchOverlay.cshtml") 297 298 @TemplateHelper.RenderPartial("Master/Partials/GlobalFooter.cshtml", new GlobalFooterViewModel(Pageview)) 299 300 <script defer="" src="@TemplateHelper.GetRevisionNumber(pathToJsManifest)"></script> 301 <script defer="" src="@TemplateHelper.GetRevisionNumber(pathToJsVendor)"></script> 302 <script defer="" src="@TemplateHelper.GetRevisionNumber(pathToJsApp)"></script> 303 @TemplateHelper.RenderPartial("Master/Partials/GlobalSchema.cshtml") 304 </body> 305 </html> 306