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_066ec5fa75824a2893a2b7f37442e975.Execute() in D:\dynamicweb.net\Solutions\Flex Media\scandinova.cloud.dynamicweb-cms.com\Files\Templates\Designs\Swift\_parsed\Swift_Email.parsed.cshtml:line 250
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>
@using Page = Dynamicweb.Content.Page
@functions
{
private Page GetBrandingPage()
{
int brandingPageId = Model.Area.Item.GetLink("BrandingPage") != null ? Model.Area.Item.GetLink("BrandingPage").PageId : 0;
return brandingPageId > 0 ? Dynamicweb.Content.Services.Pages?.GetPage(brandingPageId) : null;
}
private string GetFontsToLink()
{
Page brandingPage = GetBrandingPage();
if (brandingPage == null) return "";
List<string> fonts = new List<string>();
AddFontFamily(brandingPage, "HeaderFont", fonts);
AddFontFamily(brandingPage, "DisplayFont", fonts);
AddFontFamily(brandingPage, "BodyFont", fonts);
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)));
return fontsToLink;
}
private static void AddFontFamily(Page brandingPage, string systemName, List<string> fonts)
{
if (brandingPage.Item[systemName] == null) return;
dynamic font = Dynamicweb.Core.Converter.Deserialize<object>(brandingPage.Item[systemName].ToString());
if (font != null && font.Family != null)
{
fonts.Add(font.Family.ToString());
}
}
private string GetFontStyle(string type)
{
Page brandingPage = GetBrandingPage();
if (brandingPage == null) return "";
string fontStyle = "";
dynamic font = Dynamicweb.Core.Converter.Deserialize<object>(brandingPage.Item[type + "Font"].ToString());
if (font != null)
{
fontStyle += $"font-family:{font.Family}, sans-serif;";
fontStyle += $"font-weight:{font.SelectedVariant};";
}
fontStyle += $"line-height:{brandingPage.Item[type + "LineHeight"]};";
fontStyle += $"letter-spacing:{brandingPage.Item[type + "LetterSpacing"]}rem;";
fontStyle += $"text-transform:{brandingPage.Item[type + "Casing"]};";
return fontStyle;
}
}
@{
string swiftVersion = ReadFile("~/Files/Templates/Designs/Swift/swift_version.txt");
string lang = Pageview.Area.CultureInfo.TwoLetterISOLanguageName;
string fontsToLink = GetFontsToLink();
string bodyFontStyle = GetFontStyle("Body");
string headerFontStyle = GetFontStyle("Header");
string displayFontStyle = GetFontStyle("Display");
var backgroundColor = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(Pageview.Page.Parent).Item?.GetColor("BackgroundColor");
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional //EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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">
<head>
<!-- @swiftVersion -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="x-apple-disable-message-reformatting">
<meta http-equiv="content-type" content="text/html;">
<meta content="telephone=no" name="format-detection">
<!--[if gte mso 9]>
<xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
<o:PixelsPerInch>96</o:PixelsPerInch>
</o:OfficeDocumentSettings>
</xml>
<![endif]-->
<!--[if (gte mso 9)|(IE)]>
<style type="text/css">
table {
border-collapse: collapse;
border-spacing: 0;
mso-table-lspace: 0pt !important;
mso-table-rspace: 0pt !important;
}
</style>
<![endif]-->
<meta name="robots" content="noindex,nofollow">
<title>@Model.Item.GetString("Title")</title>
<meta property="og:title" content="@Model.Item.GetString("Title")">
<style type="text/css">
* {
box-sizing: border-box;
}
body {
margin: 0;
padding: 0;
}
html, body {
font-family:Arial,Helvetica Neue,Helvetica,sans-serif;
}
a {
color: inherit !important;
}
table,
td {
mso-table-lspace: 0pt !important;
mso-table-rspace: 0pt !important;
}
img {
-ms-interpolation-mode:bicubic;
}
a[x-apple-data-detectors] {
color: inherit !important;
font-size: inherit !important;
font-family: inherit !important;
font-weight: inherit !important;
line-height: inherit !important;
text-decoration: inherit !important;
}
#MessageViewBody a {
color: inherit !important;
font-size: inherit !important;
font-family: inherit !important;
font-weight: inherit !important;
line-height: inherit !important;
text-decoration: inherit !important;
}
p {
line-height: inherit;
}
.header {
@headerFontStyle
}
.display {
@displayFontStyle
}
.column p:first-of-type,
.column h1:first-of-type,
.column h2:first-of-type,
.column h3:first-of-type {
margin: 0;
}
.column p:last-of-type {
margin-bottom: 0;
}
@@media (max-width:660px) {
.icons-inner {
text-align: center;
}
.icons-inner td {
margin: 0 auto;
}
.row-content {
width: 100% !important;
}
.stack .column {
width: 100%;
display: block;
}
}
@@media all {
.ExternalClass {
width: 100%;
}
.ExternalClass,
.ExternalClass p,
.ExternalClass span,
.ExternalClass font,
.ExternalClass td,
.ExternalClass div {
line-height: 100%;
}
.apple-link a {
color: inherit !important;
font-family: inherit !important;
font-size: inherit !important;
font-weight: inherit !important;
line-height: inherit !important;
text-decoration: none !important;
}
}
</style>
<!--[if !mso]><!-->
<style type="text/css">
@@import url('https://fonts.googleapis.com/css?family=@(fontsToLink)&display=swap');
</style>
<link href="https://fonts.googleapis.com/css?family=@(fontsToLink)&display=swap" rel="stylesheet" type="text/css">
<!--<![endif]-->
<!--[if (gte mso 9)|(IE)]><!-->
<link href="https://fonts.googleapis.com/css?family=@(fontsToLink)&display=swap" rel="stylesheet" type="text/css">
<!--<![endif]-->
</head>
<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;">
<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%">
<tbody>
<tr>
<td style="border:0;margin:0;outline:0;padding:0;">
@inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.PageViewModel>
@if(this.Pageview is object)
{
var page = Dynamicweb.Content.Services.Pages.GetPage(Model.ID);
var settings = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(page?.Parent).Item;
bool isEmail = Model.ItemType == "Swift_Email";
if(settings is object)
{
int header = settings?.GetLink("Header").PageId ?? 0;
int footer = settings?.GetLink("Footer").PageId ?? 0;
if (isEmail)
{
<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>
}
if (Pageview.IsVisualEditorMode)
{
<div style="height:100px;"></div>
}
if (isEmail && header != 0)
{
<div class="email-header-wrapper" role="presentation" style="border:0;margin:0;outline:0;padding:0;">
@RenderGrid(header)
</div>
}
<div class="email-content-wrapper" role="presentation" style="border:0;margin:0;outline:0;padding:0;">
@Model.Grid("Grid", "Email Grid", "default:true;sort:1", "Email")
</div>
if (isEmail && footer != 0)
{
<div class="email-footer-wrapper" role="contentinfo" style="border:0;margin:0;outline:0;padding:0;">
@RenderGrid(footer)
</div>
}
}
}
</td>
</tr>
</tbody>
</table>
</body>
</html>