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_ee1c744506cf41dabbcb6010de290d1c.Execute() in D:\dynamicweb.net\Solutions\Setoff\watercryst.dw9.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>
@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.Services.Pages.GetPage(Pageview.ID);
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.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 = Pageview.CurrentParagraph.GridRowId;
var row = Dynamicweb.Services.Grids.GetGridRowById(rowId);
var rowItem = Dynamicweb.Services.Items.GetItem(row.ItemType, row.ItemId);
var rowThemeId = Dynamicweb.Core.Converter.ToString(rowItem["ColumnBackground"]);
var rowThemeParagraph = rowThemeId != null && rowThemeId != string.Empty ? Dynamicweb.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.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 linkId = item.GetLink("Link").PageId;
var itemSpacing = block.GetRawValueString("ItemSpacing", "16");
var spacing = !item.Equals(last) ? itemSpacing : "0";
var menuItem = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Dynamicweb.Services.Pages.GetPage(linkId));
if (link != null)
{
<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">
<strong style="@(foregroundColor)text-decoration:underline;font-weight:normal;@GetFontStack()">
@menuItem.Name
</strong>
</a>
}
}
}
<!--[if mso]><br/><![endif]-->
</td>
</tr>
</tbody>
</table>
|