Error executing template "Designs/Swift/_parsed/Swift_Email.parsed.cshtml"
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Operator '!=' cannot be applied to operands of type 'System.Text.Json.JsonElement' and '<null>'
at CallSite.Target(Closure, CallSite, Object, Object)
at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
at CompiledRazorTemplates.Dynamic.RazorEngine_5058195fdae74435b329c7d27249a67b.AddFontFamily(Page brandingPage, String systemName, List`1 fonts)
at CompiledRazorTemplates.Dynamic.RazorEngine_5058195fdae74435b329c7d27249a67b.GetFontsToLink()
at CompiledRazorTemplates.Dynamic.RazorEngine_5058195fdae74435b329c7d27249a67b.ExecuteAsync()
at RazorEngine.Templating.TemplateBase.Run(ExecuteContext context, TextWriter reader)
at RazorEngine.Templating.RazorEngineCore.RunTemplate(ICompiledTemplate template, TextWriter writer, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineService.Run(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.DynamicWrapperService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineServiceExtensions.RunCompile(IRazorEngineService service, String name, 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 RazorEngine.Templating.RazorEngineServiceExtensions.RunCompile(IRazorEngineService service, String name, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineServiceExtensions.RunCompile(IRazorEngineService service, String templateSource, String name, Type modelType, Object model, DynamicViewBag viewBag)
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 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 </head>
218 <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;">
219 <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%">
220 <tbody>
221 <tr>
222 <td style="border:0;margin:0;outline:0;padding:0;">
223 @inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.PageViewModel>
224
225
226 @if(this.Pageview is object)
227 {
228 var page = Dynamicweb.Content.Services.Pages.GetPage(Model.ID);
229 var settings = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(page?.Parent).Item;
230 bool isEmail = Model.ItemType == "Swift_Email";
231
232 if(settings is object)
233 {
234 int header = settings?.GetLink("Header").PageId ?? 0;
235 int footer = settings?.GetLink("Footer").PageId ?? 0;
236
237 if (isEmail)
238 {
239 <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>
240 }
241
242 if (Pageview.IsVisualEditorMode)
243 {
244 <div style="height:100px;"></div>
245 }
246
247 if (isEmail && header != 0)
248 {
249 <div class="email-header-wrapper" role="presentation" style="border:0;margin:0;outline:0;padding:0;">
250 @RenderGrid(header)
251 </div>
252 }
253 <div class="email-content-wrapper" role="presentation" style="border:0;margin:0;outline:0;padding:0;">
254 @Model.Grid("Grid", "Email Grid", "default:true;sort:1", "Email")
255 </div>
256
257 if (isEmail && footer != 0)
258 {
259 <div class="email-footer-wrapper" role="contentinfo" style="border:0;margin:0;outline:0;padding:0;">
260 @RenderGrid(footer)
261 </div>
262 }
263 }
264 }
265
266 </td>
267 </tr>
268 </tbody>
269 </table>
270 </body>
271 </html>
272