Error executing template "Designs/Swift/Swift_Email/Paragraph/Swift_EmailMenu.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
at Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Page page)
at CompiledRazorTemplates.Dynamic.RazorEngine_4e87170786984b4f95e5152e64577cba.Execute() in D:\dynamicweb.net\Solutions\Zington\ote.cloud.dynamicweb-cms.com\files\Templates\Designs\Swift\Swift_Email\Paragraph\Swift_EmailMenu.cshtml:line 81
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.ParagraphViewModel>
2
3 @functions {
4 private string GetFontStack()
5 {
6 return "font-family:initial,Arial,Helvetica Neue,Helvetica,sans-serif;";
7 }
8
9 private string GetTableReset()
10 {
11 return "border:0;margin:0;outline:0;padding:0;";
12 }
13 }
14
15 @{
16 var blockType = "menu_block";
17
18 var page = Dynamicweb.Content.Services.Pages.GetPage(Model.PageID);
19 var settings = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(page?.Parent).Item;
20 var blockId = Model.ID;
21 var block = Model.Item;
22
23 var emailContentThemeId = settings.GetRawValueString("EmailContentTheme");
24 var emailContentThemeParagraph = emailContentThemeId != null && emailContentThemeId != string.Empty ? Dynamicweb.Content.Services.Paragraphs.GetParagraph(Dynamicweb.Core.Converter.ToInt32(emailContentThemeId)) : null;
25 var emailContentTheme = emailContentThemeParagraph != null && Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(emailContentThemeParagraph).Item.GetString("CssClassName") != string.Empty ? Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(emailContentThemeParagraph)?.Item : null;
26
27 var rowId = Pageview.CurrentParagraph.GridRowId;
28 var row = Dynamicweb.Content.Services.Grids.GetGridRowById(rowId);
29 var rowItem = Dynamicweb.Content.Services.Items.GetItem(row.ItemType, row.ItemId);
30 var rowThemeId = Dynamicweb.Core.Converter.ToString(rowItem["ColumnBackground"]);
31 var rowThemeParagraph = rowThemeId != null && rowThemeId != string.Empty ? Dynamicweb.Content.Services.Paragraphs.GetParagraph(Dynamicweb.Core.Converter.ToInt32(rowThemeId)) : null;
32 var rowTheme = rowThemeParagraph != null && Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(rowThemeParagraph).Item.GetString("CssClassName") != string.Empty ? Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(rowThemeParagraph)?.Item : null;
33
34 var blockThemeId = block.GetRawValueString("Theme");
35 var blockThemeParagraph = blockThemeId != null && blockThemeId != string.Empty ? Dynamicweb.Content.Services.Paragraphs.GetParagraph(Dynamicweb.Core.Converter.ToInt32(blockThemeId)) : null;
36 var blockTheme = blockThemeParagraph != null && Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(blockThemeParagraph).Item.GetString("CssClassName") != string.Empty ? Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(blockThemeParagraph)?.Item : rowTheme is object ? rowTheme : emailContentTheme;
37
38 string backgroundColor = blockTheme != null ? "background-color: " + blockTheme.GetString("BackgroundColor") + ";" : string.Empty;
39 string foregroundColor = blockTheme != null ? "color:" + blockTheme.GetString("ForegroundColor", "inherit") + ";" : string.Empty;
40 string borderColor = blockTheme != null ? blockTheme.GetString("BorderColor", "transparent") : string.Empty;
41 string borders = block.GetRawValueString("Borders", "none");
42 string borderThicknes = block.GetRawValueString("BorderThicknes", "0") + "px";
43 string borderClass = string.Empty;
44
45 switch (borders)
46 {
47 case "top":
48 borderClass = $"border-top:{borderThicknes} solid {borderColor};";
49 break;
50 case "bottom":
51 borderClass = $"border-bottom:{borderThicknes} solid {borderColor};";
52 break;
53 case "top-bottom":
54 borderClass = $"border-top:{borderThicknes} solid {borderColor}; border-bottom:{borderThicknes} solid {borderColor}; border-left:0;border-right:0;";
55 break;
56 case "all":
57 borderClass = $"border:{borderThicknes} solid {borderColor};";
58 break;
59 }
60
61 string padding = block.GetRawValueString("Padding", "0");
62 var menuItems = block.GetItems("MenuItems");
63 var align = block.GetRawValueString("Align", "center");
64 var layout = block.GetRawValueString("Layout", "horizontal");
65 var fontSize = block.GetRawValueString("FontSize", "16");
66 }
67
68 <table id="@blockId" class="@blockType" align="@align" border="0" cellpadding="0" cellspacing="0" role="presentation" style="mso-table-lspace:0pt;mso-table-rspace:0pt;mso-line-height-rule:exactly;@GetTableReset()color:inherit;width:100%;@(backgroundColor)">
69 <tbody>
70 <tr style="@GetTableReset()">
71 <td style="mso-table-lspace:0pt;mso-table-rspace:0pt;font-weight:400;text-align:@align;vertical-align:top;@(backgroundColor)@(foregroundColor)@GetTableReset()padding:@(padding)px;@(borderClass)font-size:@(fontSize)px;" width="100%">
72 @if (menuItems != null)
73 {
74 var last = menuItems.Last();
75 foreach (var item in menuItems)
76 {
77 var link = item.GetLink("Link")?.Url ?? null;
78 var linkId = item.GetLink("Link").PageId;
79 var itemSpacing = block.GetRawValueString("ItemSpacing", "16");
80 var spacing = !item.Equals(last) ? itemSpacing : "0";
81 var menuItem = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Dynamicweb.Content.Services.Pages.GetPage(linkId));
82
83 if (link != null)
84 {
85 <a href="@link" style="text-align:@align;@(layout == "vertical" ? $"display:block !important;width:100%;padding-bottom:{spacing}px;" : $"display:inline-block !important;padding-right:{spacing}px;")@(foregroundColor)text-decoration:none;@GetFontStack()" target="_blank">
86 <strong style="@(foregroundColor)text-decoration:underline;font-weight:normal;@GetFontStack()">
87 @menuItem.Name
88 </strong>
89 </a>
90 }
91 }
92 }
93 <!--[if mso]><br/><![endif]-->
94 </td>
95 </tr>
96 </tbody>
97 </table>
98
|