Error executing template "Designs/Swift/Swift_Email/Paragraph/Swift_EmailImage.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
at CompiledRazorTemplates.Dynamic.RazorEngine_6807b71f70044b69af604c6ec5de44d1.Execute() in D:\dynamicweb.net\Solutions\Capo\duroc.cloud.dynamicweb-cms.com\files\Templates\Designs\Swift\Swift_Email\Paragraph\Swift_EmailImage.cshtml:line 89
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 @using Dynamicweb.Ecommerce.ProductCatalog
3
4 @functions {
5 private string GetTableReset()
6 {
7 return "border:0;margin:0;outline:0;padding:0;";
8 }
9 }
10
11 @{
12 string blockType = "image_block";
13
14 var page = Dynamicweb.Content.Services.Pages.GetPage(Model.PageID);
15 var settings = Dynamicweb.Frontend.ContentViewModelFactory.CreatePageInfoViewModel(page?.Parent).Item;
16 var blockId = Model.ID;
17 var block = Model.Item;
18
19 var emailContentThemeId = settings.GetRawValueString("EmailContentTheme");
20 var emailContentThemeParagraph = emailContentThemeId != null && emailContentThemeId != string.Empty ? Dynamicweb.Content.Services.Paragraphs.GetParagraph(Dynamicweb.Core.Converter.ToInt32(emailContentThemeId)) : null;
21 var emailContentTheme = emailContentThemeParagraph != null && Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(emailContentThemeParagraph).Item.GetString("CssClassName") != string.Empty ? Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(emailContentThemeParagraph)?.Item : null;
22
23 var rowId = Pageview.CurrentParagraph.GridRowId;
24 var row = Dynamicweb.Content.Services.Grids.GetGridRowById(rowId);
25 var rowItem = Dynamicweb.Content.Services.Items.GetItem(row.ItemType, row.ItemId);
26 var rowThemeId = Dynamicweb.Core.Converter.ToString(rowItem["ColumnBackground"]);
27 var rowThemeParagraph = rowThemeId != null && rowThemeId != string.Empty ? Dynamicweb.Content.Services.Paragraphs.GetParagraph(Dynamicweb.Core.Converter.ToInt32(rowThemeId)) : null;
28 var rowTheme = rowThemeParagraph != null && Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(rowThemeParagraph).Item.GetString("CssClassName") != string.Empty ? Dynamicweb.Frontend.ContentViewModelFactory.CreateParagraphInfoViewModel(rowThemeParagraph)?.Item : null;
29
30 var blockThemeId = block.GetRawValueString("Theme");
31 var blockThemeParagraph = blockThemeId != null && blockThemeId != string.Empty ? Dynamicweb.Content.Services.Paragraphs.GetParagraph(Dynamicweb.Core.Converter.ToInt32(blockThemeId)) : null;
32 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;
33
34 string padding = block.GetRawValueString("Padding", "0");
35 var link = new Dynamicweb.Frontend.LinkViewModel();
36 string linkType = block.GetRawValueString("LinkType", "page");
37
38 if (linkType == "page" && block.GetLink("PageLink") != null)
39 {
40 if (!block.GetLink("PageLink").IsExternal)
41 {
42 link = new Dynamicweb.Frontend.LinkViewModel()
43 {
44 Url = Dynamicweb.Context.Current.Request.Url.Scheme + "://" + Dynamicweb.Context.Current.Request.Url.Host + "/Default.aspx?ID=" + block.GetLink("PageLink").PageId
45 };
46 }
47 else
48 {
49 link = new Dynamicweb.Frontend.LinkViewModel()
50 {
51 Url = block.GetLink("PageLink").Url
52 };
53 }
54 }
55
56 if (linkType == "product-group")
57 {
58 IList<ProductGroupViewModel> selectedGroups = block.GetValue<IList<ProductGroupViewModel>>("ProductGroupLink");
59 IList<string> groupIds = new List<string> { };
60
61 if (selectedGroups != null)
62 {
63 foreach (var fromGroup in selectedGroups)
64 {
65 groupIds.Add(fromGroup.Id);
66 }
67 }
68
69 link = new Dynamicweb.Frontend.LinkViewModel()
70 {
71 Url = Dynamicweb.Context.Current.Request.Url.Scheme + "://" + Dynamicweb.Context.Current.Request.Url.Host + "/Default.aspx?ID=" + GetPageIdByNavigationTag("Shop") + "&GroupID=" + string.Join(",", groupIds)
72 };
73 }
74
75 if (linkType == "product")
76 {
77 ProductListViewModel products = block.GetValue<ProductListViewModel>("ProductLink");
78 IList<string> productIds = new List<string> { };
79
80 if (products != null)
81 {
82 foreach (var product in products.Products)
83 {
84 productIds.Add(product.Id);
85 }
86 }
87
88 string productParameter = productIds.Count == 1 ? "ProductID" : "MainProductId";
89 string productLink = "/" + products.Products.FirstOrDefault().GetProductLink(GetPageIdByNavigationTag("Shop"), false);
90 productLink = productIds.Count != 1 ? "/Default.aspx?ID=" + GetPageIdByNavigationTag("Shop") + "&" + productParameter + "=" + string.Join(",", productIds).Trim() : productLink;
91
92 link = new Dynamicweb.Frontend.LinkViewModel()
93 {
94 Url = Dynamicweb.Context.Current.Request.Url.Scheme + "://" + Dynamicweb.Context.Current.Request.Url.Host + productLink
95 };
96 }
97 }
98
99 <table id="@blockId" class="@blockType" align="center" 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%;">
100 <tbody>
101 <tr style="@GetTableReset()">
102 <td style="mso-table-lspace:0pt;mso-table-rspace:0pt;mso-line-height-rule:exactly;text-align:left;@GetTableReset()vertical-align:top;padding:@(padding)px" width="100%">
103 <div align="left">
104 @if (link is object && !string.IsNullOrEmpty(link.Url))
105 {
106 <a href="@link" target="_blank" style="display:block;">
107 @{ @RenderImage(padding, blockTheme) }
108 </a>
109 }
110 else
111 {
112 @RenderImage(padding, blockTheme)
113 }
114 </div>
115 </td>
116 </tr>
117 </tbody>
118 </table>
119
120 @helper RenderImage(string padding, Dynamicweb.Frontend.ItemViewModel theme)
121 {
122 var imageRatio = Model.Item.GetRawValueString("ImageAspectRatio", "4-3").ToLower();
123 var parms = new Dictionary<string, object>();
124 parms.Add("alt", Model.Item.GetString("ImageAltText"));
125 parms.Add("columns", Model.GridRowColumnCount);
126 parms.Add("padding", Dynamicweb.Core.Converter.ToInt32(padding) * 2);
127 parms.Add("imageRatio", imageRatio);
128
129 @RenderPartial("Swift_Email/Components/Image.cshtml", Model.Item.GetFile("Image") ?? new Dynamicweb.Frontend.FileViewModel(), parms)
130 }
131
|