Error executing template "Designs/Swift/_parsed/Swift_Email.parsed.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
at Dynamicweb.Content.Layouts.LayoutTemplateLocator.FindLayoutTemplateForPage(Page page)
at Dynamicweb.Frontend.Content.GetLayoutForDevice(Page page, DeviceType device)
at Dynamicweb.Frontend.Content.CreateGridContent(Int32 contentId, Boolean ignoreVisualEdit)
at Dynamicweb.Frontend.Content.RenderExternalGrid(Int32 pageId, String container)
at CompiledRazorTemplates.Dynamic.RazorEngine_40fefbeef6d649e59277b0a6ef0c5d72.Execute() in D:\dynamicweb.net\Solutions\Flex Media\hotri.cloud.dynamicweb-cms.com\files\Templates\Designs\Swift\_parsed\Swift_Email.parsed.cshtml:line 265
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 var item = brandingPage.Item[type + "Font"];
43 dynamic font = item != null ? Dynamicweb.Core.Converter.Deserialize<object>(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 h1{
169 line-height: 40px;
170 }
171
172 h2{
173 line-height: 36px;
174 }
175
176 h3{
177 line-height: 32px;
178 }
179
180 @@media (max-width:660px) {
181 .icons-inner {
182 text-align: center;
183 }
184
185 .icons-inner td {
186 margin: 0 auto;
187 }
188
189 .row-content {
190 width: 100% !important;
191 }
192
193 .stack .column {
194 width: 100%;
195 display: block;
196 }
197 }
198
199 @@media all {
200 .ExternalClass {
201 width: 100%;
202 }
203
204 .ExternalClass,
205 .ExternalClass p,
206 .ExternalClass span,
207 .ExternalClass font,
208 .ExternalClass td,
209 .ExternalClass div {
210 line-height: 100%;
211 }
212
213 .apple-link a {
214 color: inherit !important;
215 font-family: inherit !important;
216 font-size: inherit !important;
217 font-weight: inherit !important;
218 line-height: inherit !important;
219 text-decoration: none !important;
220 }
221 }
222 </style>
223 <!--[if !mso]><!-->
224 <style type="text/css">
225 @@import url('https://fonts.googleapis.com/css?family=@(fontsToLink)&display=swap');
226 </style>
227 <link href="https://fonts.googleapis.com/css?family=@(fontsToLink)&display=swap" rel="stylesheet" type="text/css">
228 <!--<![endif]-->
229 <!--[if (gte mso 9)|(IE)]><!-->
230 <link href="https://fonts.googleapis.com/css?family=@(fontsToLink)&display=swap" rel="stylesheet" type="text/css">
231 <!--<![endif]-->
232 </head>
233 <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;">
234 <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%">
235 <tbody>
236 <tr>
237 <td style="border:0;margin:0;outline:0;padding:0;">
238 @inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.PageViewModel>
239
240
241 @if(this.Pageview is object)
242 {
243 var page = Dynamicweb.Content.Services.Pages.GetPage(Model.ID);
244 var settings = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(page?.Parent).Item;
245 bool isEmail = Model.ItemType == "Swift_Email";
246
247 if(settings is object)
248 {
249 int header = settings?.GetLink("Header").PageId ?? 0;
250 int footer = settings?.GetLink("Footer").PageId ?? 0;
251
252 if (isEmail)
253 {
254 <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>
255 }
256
257 if (Pageview.IsVisualEditorMode)
258 {
259 <div style="height:100px;"></div>
260 }
261
262 if (isEmail && header != 0)
263 {
264 <div class="email-header-wrapper" role="presentation" style="border:0;margin:0;outline:0;padding:0;">
265 @RenderGrid(header)
266 </div>
267 }
268 <div class="email-content-wrapper" role="presentation" style="border:0;margin:0;outline:0;padding:0;">
269 @Model.Grid("Grid", "Email Grid", "default:true;sort:1", "Email")
270 </div>
271
272 if (isEmail && footer != 0)
273 {
274 <div class="email-footer-wrapper" role="contentinfo" style="border:0;margin:0;outline:0;padding:0;">
275 @RenderGrid(footer)
276 </div>
277 }
278 }
279 }
280
281 </td>
282 </tr>
283 </tbody>
284 </table>
285 </body>
286 </html>
287