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_0eb22b17395945b4a97e5ecc8b4e3960.Execute() in D:\dynamicweb.net\Solutions\Co3\flowconcept.cloud.dynamicweb-cms.com\Files\Templates\Designs\Swift\_parsed\Swift_Email.parsed.cshtml:line 235
   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.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 var backgroundColor = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page.Parent).Item?.GetColor("BackgroundColor"); 62 } 63 64 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional //EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 65 <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"> 66 <head> 67 <!-- @swiftVersion --> 68 <meta charset="utf-8"> 69 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 70 <meta name="x-apple-disable-message-reformatting"> 71 <meta http-equiv="content-type" content="text/html;"> 72 <meta content="telephone=no" name="format-detection"> 73 74 <!--[if gte mso 9]> 75 <xml> 76 <o:OfficeDocumentSettings> 77 <o:AllowPNG/> 78 <o:PixelsPerInch>96</o:PixelsPerInch> 79 </o:OfficeDocumentSettings> 80 </xml> 81 <![endif]--> 82 <!--[if (gte mso 9)|(IE)]> 83 <style type="text/css"> 84 table { 85 border-collapse: collapse; 86 border-spacing: 0; 87 mso-table-lspace: 0pt !important; 88 mso-table-rspace: 0pt !important; 89 } 90 </style> 91 <![endif]--> 92 93 <meta name="robots" content="noindex,nofollow"> 94 <title>@Model.Item.GetString("Title")</title> 95 <meta property="og:title" content="@Model.Item.GetString("Title")"> 96 <style type="text/css"> 97 * { 98 box-sizing: border-box; 99 } 100 101 body { 102 margin: 0; 103 padding: 0; 104 } 105 106 html, body { 107 font-family:Arial,Helvetica Neue,Helvetica,sans-serif; 108 } 109 110 a { 111 color: inherit !important; 112 } 113 114 table, 115 td { 116 mso-table-lspace: 0pt !important; 117 mso-table-rspace: 0pt !important; 118 } 119 120 img { 121 -ms-interpolation-mode:bicubic; 122 } 123 124 a[x-apple-data-detectors] { 125 color: inherit !important; 126 font-size: inherit !important; 127 font-family: inherit !important; 128 font-weight: inherit !important; 129 line-height: inherit !important; 130 text-decoration: inherit !important; 131 } 132 133 #MessageViewBody a { 134 color: inherit !important; 135 font-size: inherit !important; 136 font-family: inherit !important; 137 font-weight: inherit !important; 138 line-height: inherit !important; 139 text-decoration: inherit !important; 140 } 141 142 p { 143 line-height: inherit; 144 } 145 146 .header { 147 @headerFontStyle 148 } 149 150 .display { 151 @displayFontStyle 152 } 153 154 .column p:first-of-type, 155 .column h1:first-of-type, 156 .column h2:first-of-type, 157 .column h3:first-of-type { 158 margin: 0; 159 } 160 161 .column p:last-of-type { 162 margin-bottom: 0; 163 } 164 165 @@media (max-width:660px) { 166 .icons-inner { 167 text-align: center; 168 } 169 170 .icons-inner td { 171 margin: 0 auto; 172 } 173 174 .row-content { 175 width: 100% !important; 176 } 177 178 .stack .column { 179 width: 100%; 180 display: block; 181 } 182 } 183 184 @@media all { 185 .ExternalClass { 186 width: 100%; 187 } 188 189 .ExternalClass, 190 .ExternalClass p, 191 .ExternalClass span, 192 .ExternalClass font, 193 .ExternalClass td, 194 .ExternalClass div { 195 line-height: 100%; 196 } 197 198 .apple-link a { 199 color: inherit !important; 200 font-family: inherit !important; 201 font-size: inherit !important; 202 font-weight: inherit !important; 203 line-height: inherit !important; 204 text-decoration: none !important; 205 } 206 } 207 </style> 208 <!--[if !mso]><!--> 209 <style type="text/css"> 210 @@import url('https://fonts.googleapis.com/css?family=@(fontsToLink)&display=swap'); 211 </style> 212 <link href="https://fonts.googleapis.com/css?family=@(fontsToLink)&display=swap" rel="stylesheet" type="text/css"> 213 <!--<![endif]--> 214 <!--[if (gte mso 9)|(IE)]><!--> 215 <link href="https://fonts.googleapis.com/css?family=@(fontsToLink)&display=swap" rel="stylesheet" type="text/css"> 216 <!--<![endif]--> 217 <link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>👋</text></svg>"> 218 </head> 219 <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;"> 220 <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%"> 221 <tbody> 222 <tr> 223 <td style="border:0;margin:0;outline:0;padding:0;"> 224 @inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.PageViewModel> 225 226 227 @if(this.Pageview is object) 228 { 229 var page = Dynamicweb.Services.Pages.GetPage(Model.ID); 230 var settings = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(page?.Parent).Item; 231 bool isEmail = Model.ItemType == "Swift_Email"; 232 233 if(settings is object) 234 { 235 int header = settings?.GetLink("Header").PageId ?? 0; 236 int footer = settings?.GetLink("Footer").PageId ?? 0; 237 238 if (isEmail) 239 { 240 <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> 241 } 242 243 if (Pageview.IsVisualEditorMode) 244 { 245 <div style="height:100px;"></div> 246 } 247 248 if (isEmail && header != 0) 249 { 250 <div class="email-header-wrapper" role="presentation" style="border:0;margin:0;outline:0;padding:0;"> 251 @RenderGrid(header) 252 </div> 253 } 254 <div class="email-content-wrapper" role="presentation" style="border:0;margin:0;outline:0;padding:0;"> 255 @Model.Grid("Grid", "Email Grid", "default:true;sort:1", "Email") 256 </div> 257 258 if (isEmail && footer != 0) 259 { 260 <div class="email-footer-wrapper" role="contentinfo" style="border:0;margin:0;outline:0;padding:0;"> 261 @RenderGrid(footer) 262 </div> 263 } 264 } 265 } 266 267 </td> 268 </tr> 269 </tbody> 270 </table> 271 </body> 272 </html> 273