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