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_9f5a98d0829141909893053726e5921f.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.ParagraphViewModel>
@functions {
private string GetFontStack()
{
return "font-family:initial,Arial,Helvetica Neue,Helvetica,sans-serif;";
}
private string GetTableReset()
{
return "border:0;margin:0;outline:0;padding:0;";
}
}
@{
var blockType = "menu_block";
var page = Dynamicweb.Content.Services.Pages.GetPage(Model.PageID);
var settings = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(page?.Parent).Item;
var blockId = Model.ID;
var block = Model.Item;
var emailContentThemeId = settings.GetRawValueString("EmailContentTheme");
var emailContentThemeParagraph = emailContentThemeId != null && emailContentThemeId != string.Empty ? Dynamicweb.Content.Services.Paragraphs.GetParagraph(Dynamicweb.Core.Converter.ToInt32(emailContentThemeId)) : null;
var emailContentTheme = emailContentThemeParagraph != null && Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(emailContentThemeParagraph).Item.GetString("CssClassName") != string.Empty ? Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(emailContentThemeParagraph)?.Item : null;
var rowId = Dynamicweb.Content.Services.Paragraphs.GetParagraph(blockId).GridRowId;
var row = Dynamicweb.Content.Services.Grids.GetGridRowById(rowId);
var rowItem = Dynamicweb.Content.Services.Items.GetItem(row.ItemType, row.ItemId);
var rowThemeId = Dynamicweb.Core.Converter.ToString(rowItem["ColumnBackground"]);
var rowThemeParagraph = rowThemeId != null && rowThemeId != string.Empty ? Dynamicweb.Content.Services.Paragraphs.GetParagraph(Dynamicweb.Core.Converter.ToInt32(rowThemeId)) : null;
var rowTheme = rowThemeParagraph != null && Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(rowThemeParagraph).Item.GetString("CssClassName") != string.Empty ? Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(rowThemeParagraph)?.Item : null;
var blockThemeId = block.GetRawValueString("Theme");
var blockThemeParagraph = blockThemeId != null && blockThemeId != string.Empty ? Dynamicweb.Content.Services.Paragraphs.GetParagraph(Dynamicweb.Core.Converter.ToInt32(blockThemeId)) : null;
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;
string backgroundColor = blockTheme != null ? "background-color: " + blockTheme.GetString("BackgroundColor") + ";" : string.Empty;
string foregroundColor = blockTheme != null ? "color:" + blockTheme.GetString("ForegroundColor", "inherit") + ";" : string.Empty;
string borderColor = blockTheme != null ? blockTheme.GetString("BorderColor", "transparent") : string.Empty;
string borders = block.GetRawValueString("Borders", "none");
string borderThicknes = block.GetRawValueString("BorderThicknes", "0") + "px";
string borderClass = string.Empty;
switch (borders)
{
case "top":
borderClass = $"border-top:{borderThicknes} solid {borderColor};";
break;
case "bottom":
borderClass = $"border-bottom:{borderThicknes} solid {borderColor};";
break;
case "top-bottom":
borderClass = $"border-top:{borderThicknes} solid {borderColor}; border-bottom:{borderThicknes} solid {borderColor}; border-left:0;border-right:0;";
break;
case "all":
borderClass = $"border:{borderThicknes} solid {borderColor};";
break;
}
string padding = block.GetRawValueString("Padding", "0");
var menuItems = block.GetItems("MenuItems");
var align = block.GetRawValueString("Align", "center");
var layout = block.GetRawValueString("Layout", "horizontal");
var fontSize = block.GetRawValueString("FontSize", "16");
}
<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)">
<tbody>
<tr style="@GetTableReset()">
<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%">
@if (menuItems != null)
{
var last = menuItems.Last();
foreach (var item in menuItems)
{
var link = item.GetLink("Link")?.Url ?? null;
var itemSpacing = block.GetRawValueString("ItemSpacing", "16");
var spacing = !item.Equals(last) ? itemSpacing : "0";
if (link != null)
{
var linkId = item.GetLink("Link").PageId;
var menuItem = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Dynamicweb.Content.Services.Pages.GetPage(linkId));
link = Dynamicweb.Context.Current.Request.Url.Scheme + "://" + Dynamicweb.Context.Current.Request.Url.Host + "/Default.aspx?id=" + linkId;
<a href="@link" style="text-align:@align;@(layout == "vertical" ? $"display:block !important;width:100%;padding-bottom:{spacing}px;" : $"display:inline-block !important;margin-right:{spacing}px;")@(foregroundColor)text-decoration:none;@GetFontStack()" target="_blank">
<strong style="@(foregroundColor)text-decoration:underline;font-weight:normal;@GetFontStack()">
@menuItem.Name
</strong>
</a>
}
}
}
<!--[if mso]><br/><![endif]-->
</td>
</tr>
</tbody>
</table>
|