Error executing template "Designs/Swift/_parsed/Swift_Email.parsed.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at CompiledRazorTemplates.Dynamic.RazorEngine_3620ac27464c4460ae52a0f1446c0efd.Execute() in E:\Dynamicweb.net\Solutions\Dynamicweb\dw2022.cloud.dynamicweb-cms.com\Files\Templates\Designs\Swift\_parsed\Swift_Email.parsed.cshtml:line 236
   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 Page = Dynamicweb.Content.Page 3 4 @functions 5 { 6 private Page GetBrandingPage() 7 { 8 int brandingPageId = Model.Area.Item.GetLink("BrandingPage") != null ? Model.Area.Item.GetLink("BrandingPage").PageId : 0; 9 return brandingPageId > 0 ? Dynamicweb.Content.Services.Pages?.GetPage(brandingPageId) : null; 10 } 11 12 private string GetFontsToLink() 13 { 14 Page brandingPage = GetBrandingPage(); 15 if (brandingPage == null) return ""; 16 17 List<string> fonts = new List<string>(); 18 AddFontFamily(brandingPage, "HeaderFont", fonts); 19 AddFontFamily(brandingPage, "DisplayFont", fonts); 20 AddFontFamily(brandingPage, "BodyFont", fonts); 21 22 var fontsToLink = string.Join("%7C", fonts.Where(x => !string.IsNullOrEmpty(x)).Distinct().Select(x => string.Format("{0}:100,200,300,400,500,600,700,800,900", x))); 23 return fontsToLink; 24 } 25 26 private static void AddFontFamily(Page brandingPage, string systemName, List<string> fonts) 27 { 28 if (brandingPage.Item[systemName] == null) return; 29 dynamic font = Dynamicweb.Core.Converter.Deserialize<object>(brandingPage.Item[systemName].ToString()); 30 if (font != null && font.Family != null) 31 { 32 fonts.Add(font.Family.ToString()); 33 } 34 } 35 36 private string GetFontStyle(string type) 37 { 38 Page brandingPage = GetBrandingPage(); 39 if (brandingPage == null) return ""; 40 41 string fontStyle = ""; 42 dynamic font = Dynamicweb.Core.Converter.Deserialize<object>(brandingPage.Item[type + "Font"].ToString()); 43 if (font != null) 44 { 45 fontStyle += $"font-family:{font.Family}, sans-serif;"; 46 fontStyle += $"font-weight:{font.SelectedVariant};"; 47 } 48 fontStyle += $"line-height:{brandingPage.Item[type + "LineHeight"]};"; 49 fontStyle += $"letter-spacing:{brandingPage.Item[type + "LetterSpacing"]}rem;"; 50 fontStyle += $"text-transform:{brandingPage.Item[type + "Casing"]};"; 51 return fontStyle; 52 } 53 } 54 @{ 55 string swiftVersion = ReadFile("/Files/Templates/Designs/Swift/swift_version.txt"); 56 string lang = Pageview.Area.CultureInfo.TwoLetterISOLanguageName; 57 string fontsToLink = GetFontsToLink(); 58 string bodyFontStyle = GetFontStyle("Body"); 59 string headerFontStyle = GetFontStyle("Header"); 60 string displayFontStyle = GetFontStyle("Display"); 61 62 var pageViewModel = Pageview?.Page?.Parent != null ? Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page.Parent) : null; 63 var backgroundColor = pageViewModel != null ? pageViewModel.Item?.GetColor("BackgroundColor") : null; 64 } 65 66 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional //EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 67 <html style="border:0;margin:0;outline:0;padding:0" xmlns="http://www.w3.org/1999/xhtml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:v="urn:schemas-microsoft-com:vml" lang="@lang"> 68 <head> 69 <!-- @swiftVersion --> 70 <meta charset="utf-8"> 71 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 72 <meta name="x-apple-disable-message-reformatting"> 73 <meta http-equiv="content-type" content="text/html;"> 74 <meta content="telephone=no" name="format-detection"> 75 76 <!--[if gte mso 9]> 77 <xml> 78 <o:OfficeDocumentSettings> 79 <o:AllowPNG/> 80 <o:PixelsPerInch>96</o:PixelsPerInch> 81 </o:OfficeDocumentSettings> 82 </xml> 83 <![endif]--> 84 <!--[if (gte mso 9)|(IE)]> 85 <style type="text/css"> 86 table { 87 border-collapse: collapse; 88 border-spacing: 0; 89 mso-table-lspace: 0pt !important; 90 mso-table-rspace: 0pt !important; 91 } 92 </style> 93 <![endif]--> 94 95 <meta name="robots" content="noindex,nofollow"> 96 <title>@Model.Item.GetString("Title")</title> 97 <meta property="og:title" content="@Model.Item.GetString("Title")"> 98 <style type="text/css"> 99 * { 100 box-sizing: border-box; 101 } 102 103 body { 104 margin: 0; 105 padding: 0; 106 } 107 108 html, body { 109 font-family:Arial,Helvetica Neue,Helvetica,sans-serif; 110 } 111 112 a { 113 color: inherit !important; 114 } 115 116 table, 117 td { 118 mso-table-lspace: 0pt !important; 119 mso-table-rspace: 0pt !important; 120 } 121 122 img { 123 -ms-interpolation-mode:bicubic; 124 } 125 126 a[x-apple-data-detectors] { 127 color: inherit !important; 128 font-size: inherit !important; 129 font-family: inherit !important; 130 font-weight: inherit !important; 131 line-height: inherit !important; 132 text-decoration: inherit !important; 133 } 134 135 #MessageViewBody a { 136 color: inherit !important; 137 font-size: inherit !important; 138 font-family: inherit !important; 139 font-weight: inherit !important; 140 line-height: inherit !important; 141 text-decoration: inherit !important; 142 } 143 144 p { 145 line-height: inherit; 146 } 147 148 .header { 149 @headerFontStyle 150 } 151 152 .display { 153 @displayFontStyle 154 } 155 156 .column p:first-of-type, 157 .column h1:first-of-type, 158 .column h2:first-of-type, 159 .column h3:first-of-type { 160 margin: 0; 161 } 162 163 .column p:last-of-type { 164 margin-bottom: 0; 165 } 166 167 @@media (max-width:660px) { 168 .icons-inner { 169 text-align: center; 170 } 171 172 .icons-inner td { 173 margin: 0 auto; 174 } 175 176 .row-content { 177 width: 100% !important; 178 } 179 180 .stack .column { 181 width: 100%; 182 display: block; 183 } 184 } 185 186 @@media all { 187 .ExternalClass { 188 width: 100%; 189 } 190 191 .ExternalClass, 192 .ExternalClass p, 193 .ExternalClass span, 194 .ExternalClass font, 195 .ExternalClass td, 196 .ExternalClass div { 197 line-height: 100%; 198 } 199 200 .apple-link a { 201 color: inherit !important; 202 font-family: inherit !important; 203 font-size: inherit !important; 204 font-weight: inherit !important; 205 line-height: inherit !important; 206 text-decoration: none !important; 207 } 208 } 209 </style> 210 <!--[if !mso]><!--> 211 <style type="text/css"> 212 @@import url('https://fonts.googleapis.com/css?family=@(fontsToLink)&display=swap'); 213 </style> 214 <link href="https://fonts.googleapis.com/css?family=@(fontsToLink)&display=swap" rel="stylesheet" type="text/css"> 215 <!--<![endif]--> 216 <!--[if (gte mso 9)|(IE)]><!--> 217 <link href="https://fonts.googleapis.com/css?family=@(fontsToLink)&display=swap" rel="stylesheet" type="text/css"> 218 <!--<![endif]--> 219 </head> 220 <body style="font-family:Arial,Helvetica Neue,Helvetica,sans-serif;@(bodyFontStyle)border:0;margin:0;outline:0;padding:0;-webkit-font-smoothing:antialiased;-webkit-text-size-adjust:none;text-size-adjust:none;mso-line-height-rule:exactly;line-height:1;"> 221 <table border="0" cellpadding="0" cellspacing="0" role="presentation" style="mso-table-lspace:0pt;mso-table-rspace:0pt;mso-line-height-rule:exactly;@(bodyFontStyle)border:0;border-collapse:collapse;border-spacing:0;margin:0;outline:0;padding:0;" width="100%"> 222 <tbody> 223 <tr> 224 <td style="border:0;margin:0;outline:0;padding:0;"> 225 @inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.PageViewModel> 226 227 228 @if(this.Pageview is object) 229 { 230 var page = Dynamicweb.Content.Services.Pages.GetPage(Model.ID); 231 var settings = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(page?.Parent).Item; 232 bool isEmail = Model.ItemType == "Swift_Email"; 233 234 if(settings is object) 235 { 236 int header = settings?.GetLink("Header").PageId ?? 0; 237 int footer = settings?.GetLink("Footer").PageId ?? 0; 238 239 if (isEmail) 240 { 241 <span class="preheader" style="color:transparent;display:none;height:0;max-height:0;max-width:0;opacity:0;overflow:hidden;mso-hide:all;visibility:hidden;width:0;">{{EmailMarketing:Email.PreHeader.Clean}}</span> 242 } 243 244 if (Pageview.IsVisualEditorMode) 245 { 246 <div style="height:100px;"></div> 247 } 248 249 if (isEmail && header != 0) 250 { 251 <div class="email-header-wrapper" role="presentation" style="border:0;margin:0;outline:0;padding:0;"> 252 @RenderGrid(header) 253 </div> 254 } 255 <div class="email-content-wrapper" role="presentation" style="border:0;margin:0;outline:0;padding:0;"> 256 @Model.Grid("Grid", "Email Grid", "default:true;sort:1", "Email") 257 </div> 258 259 if (isEmail && footer != 0) 260 { 261 <div class="email-footer-wrapper" role="contentinfo" style="border:0;margin:0;outline:0;padding:0;"> 262 @RenderGrid(footer) 263 </div> 264 } 265 } 266 } 267 268 </td> 269 </tr> 270 </tbody> 271 </table> 272 </body> 273 </html> 274