Share this:
Error executing template "Designs/Standard/ItemPublisher/List/Staffs-extra.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at CompiledRazorTemplates.Dynamic.RazorEngine_f9064bba13f441cb8f040894947e4d6b.Execute() in E:\dynamicweb.net\solutions\Skabertrangweb\balticcontrol.net.dynamicweb-cms.com\files\Templates\Designs\Standard\ItemPublisher\List\Staffs-extra.cshtml:line 224
   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.b__0(TextWriter writer)
   at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
   at Dynamicweb.Rendering.Template.RenderRazorTemplate()

1 @inherits Dynamicweb.Rendering.RazorTemplateBase<Dynamicweb.Rendering.RazorTemplateModel<Dynamicweb.Rendering.Template>> 2 @using System.Text.RegularExpressions 3 @inherits Dynamicweb.Rendering.RazorTemplateBase<Dynamicweb.Rendering.RazorTemplateModel<Dynamicweb.Rendering.Template>> 4 @using System.IO 5 @using System.Web 6 @helper RenderGoogleConversion(string conversionId, string conversionLanguage, string conversionFormat, string conversionColor, string conversionLabel, string conversionValue, string conversionCurrency, bool remarketingOnly) { 7 var googleConversionId = conversionId; 8 var googleConversionLanguage = string.IsNullOrWhiteSpace(conversionLanguage) ? "en" : conversionLanguage; 9 var googleConversionFormat = string.IsNullOrWhiteSpace(conversionFormat) ? "3" : conversionFormat; 10 var googleConversionColor = string.IsNullOrWhiteSpace(conversionColor) ? "ffffff" : conversionColor; 11 var googleConversionLabel = conversionLabel; 12 var googleConversionValue = string.IsNullOrWhiteSpace(conversionValue) ? "0" : conversionValue; 13 var googleConversionCurrency = string.IsNullOrWhiteSpace(conversionCurrency) ? "DKK" : conversionCurrency; 14 var googleRemarketingOnly = remarketingOnly; 15 16 <!-- Google Code for the Conversion Page --> 17 <script type="text/javascript"> 18 /* <![CDATA[ */ 19 var google_conversion_id = @(googleConversionId); 20 var google_conversion_language = '@(googleConversionLanguage)'; 21 var google_conversion_format = '@(googleConversionFormat)'; 22 var google_conversion_color = '@(googleConversionColor)'; 23 var google_conversion_label = '@(googleConversionLabel)'; 24 var google_conversion_value = @(googleConversionValue); 25 var google_conversion_currency = '@(googleConversionCurrency)'; 26 var google_remarketing_only = @(googleRemarketingOnly ? "true" : "false"); 27 /* ]]> */ 28 </script> 29 <script type="text/javascript" src="https://www.googleadservices.com/pagead/conversion.js"></script> 30 <noscript> 31 <div style="display: inline;"> 32 <img src="https://www.googleadservices.com/pagead/conversion/@(googleConversionId)/?value=@(googleConversionValue)&amp;currency_code=@(googleConversionCurrency)&amp;label=@(googleConversionLabel)&amp;guid=ON&amp;script=0" alt="" width="1" height="1" style="border-style: none;" /> 33 </div> 34 </noscript> 35 } 36 @helper RenderGoogleAnalyticsEcommerceTracking(string transactionId, string affiliation, string revenue, string shipping, string tax, string currency, string[][] orderLines) { 37 <script type="text/javascript"> 38 if (!window.skabertrang_ga_ecommerce_callbacks) 39 window.skabertrang_ga_ecommerce_callbacks = []; 40 41 (function() { 42 var orderLines = @(Newtonsoft.Json.JsonConvert.SerializeObject(orderLines)); 43 44 window.skabertrang_ga_ecommerce_callbacks.push(function() { 45 ga('require', 'ecommerce'); 46 47 ga('ecommerce:addTransaction', { 48 'id' : '@(transactionId)', 49 'affiliation' : '@(affiliation)', 50 'revenue' : '@(revenue)', 51 'shipping' : '@(shipping)', 52 'tax' : '@(tax)', 53 'currency' : '@(currency)' 54 }); 55 56 if (orderLines && orderLines.length) { 57 for (var i = 0; i < orderLines.length; i++) { 58 ga('ecommerce:addItem', { 59 'id' : '@(transactionId)', 60 'name' : orderLines[i][1], 61 'sku' : orderLines[i][0], 62 'category' : orderLines[i][2], 63 'price' : orderLines[i][3], 64 'quantity' : orderLines[i][4], 65 'currency' : '@(currency)' 66 }); 67 } 68 } 69 70 ga('ecommerce:send'); 71 }); 72 })(); 73 </script> 74 } 75 @functions { 76 string mediaOverlay(string filePath, string filePathThumb = "", string caption = "", string group = "", string alt = "", string title = "", string extraAttributes = "") { 77 78 filePathThumb = !string.IsNullOrWhiteSpace(filePathThumb) ? filePathThumb : filePath; 79 group = !string.IsNullOrWhiteSpace(group) ? group : !string.IsNullOrWhiteSpace(GetString("ParagraphID")) ? GetString("ParagraphID") : "imageGroup"; 80 81 return "<a href='" + filePath + "' class='media-overlay' data-lightbox='" + group + "' data-title='" + caption + "'><img src='"+filePathThumb+"' alt='" + alt + "' title='" + title + "'/></a>"; 82 83 } 84 85 string GetImage(string image, int width, int height, int compression, int crop, string colorSpace, bool doNotUpscale) { 86 // Crop 87 // 0 = Center 88 // 1 = From upper left 89 // 2 = From lower left 90 // 3 = From lower right 91 // 4 = From upper right 92 // 5 = Keep aspect ratio 93 // 6 = Fit image 94 95 // ColorSpace 96 // rgb 97 // cmyk 98 // grayscale 99 100 var param = new List<string>(); 101 102 param.Add("Image=" + image); 103 param.Add("Format=" + Path.GetExtension(image).Substring(1)); 104 105 if (width > 0) { 106 param.Add("Width=" + width); 107 } 108 109 if (height > 0) { 110 param.Add("Height=" + height); 111 } 112 113 param.Add("Compression=" + compression); 114 param.Add("Crop=" + crop); 115 param.Add("ColorSpace=" + colorSpace); 116 param.Add("DoNotUpscale=" + (doNotUpscale ? "True" : "False")); 117 118 return "/Admin/Public/GetImage.ashx?" + string.Join("&amp;", param); 119 } 120 121 string GetImagePlaceholder(int width, int height) { 122 return GetImagePlaceholder(width, height, null, null, null); 123 } 124 125 string GetImagePlaceholder(int width, int height, string backgroundColor, string textColor, string text) { 126 var r = "https://placehold.it/" + width; 127 128 if (height > 0) { 129 r += "x" + height; 130 } 131 132 if (!string.IsNullOrWhiteSpace(backgroundColor) && !string.IsNullOrWhiteSpace(textColor)) { 133 r += "/" + backgroundColor; 134 r += "/" + textColor; 135 } 136 137 if (!string.IsNullOrWhiteSpace(text)) { 138 r += "?text=" + text.Replace(" ", "+"); 139 } 140 141 return r; 142 } 143 144 145 T LoadContextItem<T>(string key) { 146 var obj = HttpContext.Current.Items != null ? HttpContext.Current.Items[key] : null; 147 148 if (obj == null) { 149 return default(T); 150 } 151 152 return (T)obj; 153 } 154 155 void SaveContextItem(string key, object value) { 156 if (HttpContext.Current.Items != null && value != null) { 157 HttpContext.Current.Items[key] = value; 158 } 159 } 160 161 string PathCombine(params string[] paths) { 162 return Path.Combine(paths); 163 } 164 165 string NullIfEmpty(string value) { 166 return string.IsNullOrEmpty(value) ? null : value; 167 } 168 169 string NullIfWhiteSpace(string value) { 170 return string.IsNullOrWhiteSpace(value) ? null : value; 171 } 172 173 string ToJson(object value) { 174 return ToJson(value, false); 175 } 176 177 string ToJson(object value, bool indented) { 178 return Newtonsoft.Json.JsonConvert.SerializeObject( 179 value, 180 indented ? Newtonsoft.Json.Formatting.Indented : Newtonsoft.Json.Formatting.None, 181 new Newtonsoft.Json.Converters.IsoDateTimeConverter { DateTimeFormat = "yyyyMMdd'T'HHmmss" } 182 ); 183 } 184 185 void AddCssFile(params string[] files) { 186 var list = LoadContextItem<List<string>>("SB.CssFiles"); 187 188 if (list == null) { 189 list = new List<string>(); 190 } 191 192 foreach (var file in files) { 193 if (!list.Contains(file, StringComparer.OrdinalIgnoreCase)) { 194 list.Add(file); 195 } 196 } 197 198 SaveContextItem("SB.CssFiles", list); 199 } 200 201 void AddJsFile(params string[] files) { 202 var list = LoadContextItem<List<string>>("SB.JsFiles"); 203 204 if (list == null) { 205 list = new List<string>(); 206 } 207 208 foreach (var file in files) { 209 if (!list.Contains(file, StringComparer.OrdinalIgnoreCase)) { 210 list.Add(file); 211 } 212 } 213 214 SaveContextItem("SB.JsFiles", list); 215 } 216 } 217 @{ 218 var designBaseUrl = GetString("Template:DesignBaseUrl"); 219 var assetsBaseUrl = designBaseUrl + "assets/"; 220 221 var items = GetLoop("ItemPublisher:Items.List"); 222 var chk = true; 223 224 if (Pageview.Page.Item.ContainsKey("Staffs")) { 225 var pageStaffs = (string)Pageview.Page.Item["Staffs"]; 226 227 if (!string.IsNullOrWhiteSpace(pageStaffs)) { 228 var itemsFilter = items.Where(o => { 229 return pageStaffs.Split(',').Any(p => p == o.GetString("ItemPublisher:Item.Field.Id")); 230 }).ToList(); 231 232 if (itemsFilter.Any()) { 233 items = itemsFilter; 234 chk = false; 235 } 236 } 237 } 238 239 if (chk) { 240 items.Clear(); 241 } 242 } 243 <div class="list-staffs-extra"> 244 @if (items.Any()) { 245 <div class="fg-container"> 246 @foreach (var item in items) { 247 var pageId = item.GetInteger("ItemPublisher:Item.Field.PageId"); 248 var name = item.GetString("ItemPublisher:Item.Name"); 249 var title = item.GetString("ItemPublisher:Item.Title"); 250 var image = item.GetString("ItemPublisher:Item.Image"); 251 var email = item.GetString("ItemPublisher:Item.Email"); 252 var phoneNumber = item.GetString("ItemPublisher:Item.PhoneNumber"); 253 var mobileNumber = item.GetString("ItemPublisher:Item.MobileNumber"); 254 var teaserText = item.GetString("ItemPublisher:Item.TeaserText"); 255 256 if (string.IsNullOrWhiteSpace(image)) { 257 image = designBaseUrl + "img/avatar.jpg"; 258 } 259 260 <div class="list-staff"> 261 <div class="fg-row fg-middle-xs"> 262 <div class="fg-col-xs-6 fg-col-sm-3 fg-col-md-2"> 263 <div class="list-staff-image"> 264 <img src="@(image)" alt="" class="img-responsive"> 265 </div> 266 </div> 267 <div class="fg-col-xs-6 fg-col-sm-3 fg-col-md-3"> 268 <div class="list-staff-info"> 269 <h4> 270 @(name) 271 @if (!string.IsNullOrWhiteSpace(title)) { 272 <br><small>@(title)</small> 273 } 274 </h4> 275 <p> 276 @if (!string.IsNullOrWhiteSpace(phoneNumber)) { 277 var href = Regex.Replace(phoneNumber, "[^0-9+]", string.Empty); 278 <a href="tel:@(href)">@(phoneNumber)</a><br> 279 } 280 @if (!string.IsNullOrWhiteSpace(mobileNumber)) { 281 var href = Regex.Replace(mobileNumber, "[^0-9+]", string.Empty); 282 <a href="tel:@(href)">@(mobileNumber)</a><br> 283 } 284 @if (!string.IsNullOrWhiteSpace(email)) { 285 <a href="mailto:@(email)">@(email)</a><br> 286 } 287 </p> 288 </div> 289 </div> 290 <div class="fg-col-xs-12 fg-col-sm-6 fg-col-md-7"> 291 <div class="list-staff-teaser"> 292 @(teaserText) 293 </div> 294 </div> 295 </div> 296 </div> 297 } 298 </div> 299 } 300 </div>
Error executing template "Designs/Standard/ItemPublisher/List/Cases-extra.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at CompiledRazorTemplates.Dynamic.RazorEngine_07b3662da6d84fb0b26296fbc26118ac.Execute() in E:\dynamicweb.net\solutions\Skabertrangweb\balticcontrol.net.dynamicweb-cms.com\files\Templates\Designs\Standard\ItemPublisher\List\Cases-extra.cshtml:line 247
   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.b__0(TextWriter writer)
   at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
   at Dynamicweb.Rendering.Template.RenderRazorTemplate()

1 @inherits Dynamicweb.Rendering.RazorTemplateBase<Dynamicweb.Rendering.RazorTemplateModel<Dynamicweb.Rendering.Template>> 2 @inherits Dynamicweb.Rendering.RazorTemplateBase<Dynamicweb.Rendering.RazorTemplateModel<Dynamicweb.Rendering.Template>> 3 @using System.IO 4 @using System.Web 5 @helper RenderGoogleConversion(string conversionId, string conversionLanguage, string conversionFormat, string conversionColor, string conversionLabel, string conversionValue, string conversionCurrency, bool remarketingOnly) { 6 var googleConversionId = conversionId; 7 var googleConversionLanguage = string.IsNullOrWhiteSpace(conversionLanguage) ? "en" : conversionLanguage; 8 var googleConversionFormat = string.IsNullOrWhiteSpace(conversionFormat) ? "3" : conversionFormat; 9 var googleConversionColor = string.IsNullOrWhiteSpace(conversionColor) ? "ffffff" : conversionColor; 10 var googleConversionLabel = conversionLabel; 11 var googleConversionValue = string.IsNullOrWhiteSpace(conversionValue) ? "0" : conversionValue; 12 var googleConversionCurrency = string.IsNullOrWhiteSpace(conversionCurrency) ? "DKK" : conversionCurrency; 13 var googleRemarketingOnly = remarketingOnly; 14 15 <!-- Google Code for the Conversion Page --> 16 <script type="text/javascript"> 17 /* <![CDATA[ */ 18 var google_conversion_id = @(googleConversionId); 19 var google_conversion_language = '@(googleConversionLanguage)'; 20 var google_conversion_format = '@(googleConversionFormat)'; 21 var google_conversion_color = '@(googleConversionColor)'; 22 var google_conversion_label = '@(googleConversionLabel)'; 23 var google_conversion_value = @(googleConversionValue); 24 var google_conversion_currency = '@(googleConversionCurrency)'; 25 var google_remarketing_only = @(googleRemarketingOnly ? "true" : "false"); 26 /* ]]> */ 27 </script> 28 <script type="text/javascript" src="https://www.googleadservices.com/pagead/conversion.js"></script> 29 <noscript> 30 <div style="display: inline;"> 31 <img src="https://www.googleadservices.com/pagead/conversion/@(googleConversionId)/?value=@(googleConversionValue)&amp;currency_code=@(googleConversionCurrency)&amp;label=@(googleConversionLabel)&amp;guid=ON&amp;script=0" alt="" width="1" height="1" style="border-style: none;" /> 32 </div> 33 </noscript> 34 } 35 @helper RenderGoogleAnalyticsEcommerceTracking(string transactionId, string affiliation, string revenue, string shipping, string tax, string currency, string[][] orderLines) { 36 <script type="text/javascript"> 37 if (!window.skabertrang_ga_ecommerce_callbacks) 38 window.skabertrang_ga_ecommerce_callbacks = []; 39 40 (function() { 41 var orderLines = @(Newtonsoft.Json.JsonConvert.SerializeObject(orderLines)); 42 43 window.skabertrang_ga_ecommerce_callbacks.push(function() { 44 ga('require', 'ecommerce'); 45 46 ga('ecommerce:addTransaction', { 47 'id' : '@(transactionId)', 48 'affiliation' : '@(affiliation)', 49 'revenue' : '@(revenue)', 50 'shipping' : '@(shipping)', 51 'tax' : '@(tax)', 52 'currency' : '@(currency)' 53 }); 54 55 if (orderLines && orderLines.length) { 56 for (var i = 0; i < orderLines.length; i++) { 57 ga('ecommerce:addItem', { 58 'id' : '@(transactionId)', 59 'name' : orderLines[i][1], 60 'sku' : orderLines[i][0], 61 'category' : orderLines[i][2], 62 'price' : orderLines[i][3], 63 'quantity' : orderLines[i][4], 64 'currency' : '@(currency)' 65 }); 66 } 67 } 68 69 ga('ecommerce:send'); 70 }); 71 })(); 72 </script> 73 } 74 @functions { 75 string mediaOverlay(string filePath, string filePathThumb = "", string caption = "", string group = "", string alt = "", string title = "", string extraAttributes = "") { 76 77 filePathThumb = !string.IsNullOrWhiteSpace(filePathThumb) ? filePathThumb : filePath; 78 group = !string.IsNullOrWhiteSpace(group) ? group : !string.IsNullOrWhiteSpace(GetString("ParagraphID")) ? GetString("ParagraphID") : "imageGroup"; 79 80 return "<a href='" + filePath + "' class='media-overlay' data-lightbox='" + group + "' data-title='" + caption + "'><img src='"+filePathThumb+"' alt='" + alt + "' title='" + title + "'/></a>"; 81 82 } 83 84 string GetImage(string image, int width, int height, int compression, int crop, string colorSpace, bool doNotUpscale) { 85 // Crop 86 // 0 = Center 87 // 1 = From upper left 88 // 2 = From lower left 89 // 3 = From lower right 90 // 4 = From upper right 91 // 5 = Keep aspect ratio 92 // 6 = Fit image 93 94 // ColorSpace 95 // rgb 96 // cmyk 97 // grayscale 98 99 var param = new List<string>(); 100 101 param.Add("Image=" + image); 102 param.Add("Format=" + Path.GetExtension(image).Substring(1)); 103 104 if (width > 0) { 105 param.Add("Width=" + width); 106 } 107 108 if (height > 0) { 109 param.Add("Height=" + height); 110 } 111 112 param.Add("Compression=" + compression); 113 param.Add("Crop=" + crop); 114 param.Add("ColorSpace=" + colorSpace); 115 param.Add("DoNotUpscale=" + (doNotUpscale ? "True" : "False")); 116 117 return "/Admin/Public/GetImage.ashx?" + string.Join("&amp;", param); 118 } 119 120 string GetImagePlaceholder(int width, int height) { 121 return GetImagePlaceholder(width, height, null, null, null); 122 } 123 124 string GetImagePlaceholder(int width, int height, string backgroundColor, string textColor, string text) { 125 var r = "https://placehold.it/" + width; 126 127 if (height > 0) { 128 r += "x" + height; 129 } 130 131 if (!string.IsNullOrWhiteSpace(backgroundColor) && !string.IsNullOrWhiteSpace(textColor)) { 132 r += "/" + backgroundColor; 133 r += "/" + textColor; 134 } 135 136 if (!string.IsNullOrWhiteSpace(text)) { 137 r += "?text=" + text.Replace(" ", "+"); 138 } 139 140 return r; 141 } 142 143 144 T LoadContextItem<T>(string key) { 145 var obj = HttpContext.Current.Items != null ? HttpContext.Current.Items[key] : null; 146 147 if (obj == null) { 148 return default(T); 149 } 150 151 return (T)obj; 152 } 153 154 void SaveContextItem(string key, object value) { 155 if (HttpContext.Current.Items != null && value != null) { 156 HttpContext.Current.Items[key] = value; 157 } 158 } 159 160 string PathCombine(params string[] paths) { 161 return Path.Combine(paths); 162 } 163 164 string NullIfEmpty(string value) { 165 return string.IsNullOrEmpty(value) ? null : value; 166 } 167 168 string NullIfWhiteSpace(string value) { 169 return string.IsNullOrWhiteSpace(value) ? null : value; 170 } 171 172 string ToJson(object value) { 173 return ToJson(value, false); 174 } 175 176 string ToJson(object value, bool indented) { 177 return Newtonsoft.Json.JsonConvert.SerializeObject( 178 value, 179 indented ? Newtonsoft.Json.Formatting.Indented : Newtonsoft.Json.Formatting.None, 180 new Newtonsoft.Json.Converters.IsoDateTimeConverter { DateTimeFormat = "yyyyMMdd'T'HHmmss" } 181 ); 182 } 183 184 void AddCssFile(params string[] files) { 185 var list = LoadContextItem<List<string>>("SB.CssFiles"); 186 187 if (list == null) { 188 list = new List<string>(); 189 } 190 191 foreach (var file in files) { 192 if (!list.Contains(file, StringComparer.OrdinalIgnoreCase)) { 193 list.Add(file); 194 } 195 } 196 197 SaveContextItem("SB.CssFiles", list); 198 } 199 200 void AddJsFile(params string[] files) { 201 var list = LoadContextItem<List<string>>("SB.JsFiles"); 202 203 if (list == null) { 204 list = new List<string>(); 205 } 206 207 foreach (var file in files) { 208 if (!list.Contains(file, StringComparer.OrdinalIgnoreCase)) { 209 list.Add(file); 210 } 211 } 212 213 SaveContextItem("SB.JsFiles", list); 214 } 215 } 216 @{ 217 var lockArea = new int[] { 1, 2 }; 218 var items = new List<dynamic>(); 219 220 if (!lockArea.Contains(Pageview.AreaID)) { 221 var base_Area = Dynamicweb.Services.Areas.GetArea(2); 222 int base_FolderCases = 0; 223 if (base_Area != null && base_Area.Item.ContainsKey("Folder_Cases") && int.TryParse("" + base_Area.Item["Folder_Cases"], out base_FolderCases) && base_FolderCases != 0) { 224 var base_CaseItemPages = Dynamicweb.Services.Pages.GetPagesByParentID(Dynamicweb.Services.Pages.GetPage(base_FolderCases).ID); 225 items.AddRange( 226 base_CaseItemPages 227 .Select(o => new { 228 Id = o.ItemId, 229 PageId = o.ID, 230 Headline = (string)o.Item["Headline"], 231 Type = (string)o.Item["Type"], 232 SpotImage = (string)o.Item["SpotImage"], 233 SpotTeaserText = (string)o.Item["SpotTeaserText"], 234 PublishToFranchise = (bool)o.Item["PublishToFranchise"], 235 Sort = o.Sort 236 }) 237 .Where(o => o.PublishToFranchise) 238 .OrderBy(o => o.Sort) 239 ); 240 } 241 242 243 244 } 245 246 var pageCase = Pageview.Page; 247 var pageCaseType = pageCase.Item.ContainsKey("Type") ? (string)pageCase.Item["Type"] : string.Empty; 248 var pageCasesArea = Pageview.Area.Item.ContainsKey("Page_Cases") ? "" +Pageview.Area.Item["Page_Cases"] : string.Empty; 249 250 while (true) { 251 pageCase = pageCase.Parent; 252 253 if (pageCase == null || (bool)pageCase.IsFolder) { 254 break; 255 } 256 257 pageCaseType = pageCase.Item.ContainsKey("Type") ? ""+pageCase.Item["Type"] : pageCaseType; 258 } 259 260 var count = 4; 261 var filtered = false; 262 263 var itemsLocal = GetLoop("ItemPublisher:Items.List") 264 .Select(o => new { 265 Id = o.GetString("ItemPublisher:Item.Field.Id"), 266 PageId = o.GetInteger("ItemPublisher:Item.Field.PageId"), 267 Headline = o.GetString("ItemPublisher:Item.Headline"), 268 Type = o.GetString("ItemPublisher:Item.Type"), 269 SpotImage = o.GetString("ItemPublisher:Item.SpotImage"), 270 SpotTeaserText = o.GetString("ItemPublisher:Item.SpotTeaserText"), 271 PublishToFranchise = o.GetBoolean("ItemPublisher:Item.PublishToFranchise"), 272 Sort = o.GetInteger("ItemPublisher:Items.List.LoopCounter") 273 }) 274 .ToList(); 275 276 if (Pageview.Page.Item.ContainsKey("Cases")) { 277 var pageCases = (string)Pageview.Page.Item["Cases"]; 278 279 if (!string.IsNullOrWhiteSpace(pageCases)) { 280 var itemsFilter = itemsLocal.Where(o => pageCases.Split(',').Any(p => p == o.Id)); 281 282 if (itemsFilter.Any()) { 283 items.AddRange(itemsFilter); 284 285 count = items.Count; 286 filtered = true; 287 } 288 } 289 } 290 291 if (!filtered) { 292 items.AddRange(itemsLocal); 293 294 if (!string.IsNullOrWhiteSpace(pageCaseType)) { 295 items = items.Where(o => o.Type == pageCaseType).ToList(); 296 } 297 } 298 299 items = items.Where(o => o.PageId != Pageview.Page.ID).ToList(); 300 301 if (items.Any()) { 302 AddJsFile( 303 "https://cdnjs.cloudflare.com/ajax/libs/textfit/2.3.1/textFit.min.js", 304 "https://cdnjs.cloudflare.com/ajax/libs/jQuery.dotdotdot/1.7.4/jquery.dotdotdot.min.js" 305 ); 306 } 307 } 308 @if (items.Any()) { 309 <div class="list-cases-extra"> 310 <div class="container"> 311 <h2>@(Translate("Cases"))</h2> 312 313 <div class="row"> 314 @foreach (var item in items.Take(count)) { 315 var spotImage = item.SpotImage; 316 var spotImageGray = spotImage; 317 318 if (string.IsNullOrWhiteSpace(spotImage)) { 319 spotImage = GetImagePlaceholder(550, 340); 320 spotImageGray = spotImage; 321 } else { 322 spotImageGray = GetImage(spotImage, 550, 340, 100, 0, "grayscale", false); 323 } 324 325 <div class="col-sm-6"> 326 <a href="/Default.aspx?Id=@(item.PageId)" class="list-case" data-casetype="@(item.Type)"> 327 <div class="list-case-bg"> 328 <img src="@(spotImageGray)" alt="" class="img-responsive"> 329 <img src="@(spotImage)" alt="" class="img-responsive"> 330 </div> 331 <div class="list-case-content"> 332 <div class="list-case-headline hidden"> 333 @(item.Headline) 334 </div> 335 <p>@(item.SpotTeaserText)</p> 336 </div> 337 </a> 338 </div> 339 } 340 </div> 341 342 @if (!string.IsNullOrWhiteSpace(pageCasesArea)) { 343 <div class="text-center"> 344 <a class="btn btn-type-1" href="/Default.aspx?Id=@(pageCasesArea)" role="button">@(Translate("Se alle cases"))</a> 345 </div> 346 } 347 </div> 348 </div> 349 350 <script type="text/javascript"> 351 (function ($) { 352 function resizer() { 353 var $target = $('.list-case-headline'); 354 $target.removeClass('hidden'); 355 textFit($target, { maxFontSize: 36, alignVert: true, multiLine: true }); 356 } 357 358 function ellipsis() { 359 $('> p', '.list-case-content').dotdotdot({}); 360 } 361 362 $(window).on('load resize orientationchange', function () { 363 resizer(); 364 ellipsis(); 365 }); 366 })($); 367 </script> 368 }
Error executing template "Designs/Standard/ItemPublisher/List/News-extra.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at CompiledRazorTemplates.Dynamic.RazorEngine_0e5969bcd8784eb89a94d4a5c3c003b4.Execute() in E:\dynamicweb.net\solutions\Skabertrangweb\balticcontrol.net.dynamicweb-cms.com\files\Templates\Designs\Standard\ItemPublisher\List\News-extra.cshtml:line 221
   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.b__0(TextWriter writer)
   at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
   at Dynamicweb.Rendering.Template.RenderRazorTemplate()

1 @inherits Dynamicweb.Rendering.RazorTemplateBase<Dynamicweb.Rendering.RazorTemplateModel<Dynamicweb.Rendering.Template>> 2 @inherits Dynamicweb.Rendering.RazorTemplateBase<Dynamicweb.Rendering.RazorTemplateModel<Dynamicweb.Rendering.Template>> 3 @using System.IO 4 @using System.Web 5 @helper RenderGoogleConversion(string conversionId, string conversionLanguage, string conversionFormat, string conversionColor, string conversionLabel, string conversionValue, string conversionCurrency, bool remarketingOnly) { 6 var googleConversionId = conversionId; 7 var googleConversionLanguage = string.IsNullOrWhiteSpace(conversionLanguage) ? "en" : conversionLanguage; 8 var googleConversionFormat = string.IsNullOrWhiteSpace(conversionFormat) ? "3" : conversionFormat; 9 var googleConversionColor = string.IsNullOrWhiteSpace(conversionColor) ? "ffffff" : conversionColor; 10 var googleConversionLabel = conversionLabel; 11 var googleConversionValue = string.IsNullOrWhiteSpace(conversionValue) ? "0" : conversionValue; 12 var googleConversionCurrency = string.IsNullOrWhiteSpace(conversionCurrency) ? "DKK" : conversionCurrency; 13 var googleRemarketingOnly = remarketingOnly; 14 15 <!-- Google Code for the Conversion Page --> 16 <script type="text/javascript"> 17 /* <![CDATA[ */ 18 var google_conversion_id = @(googleConversionId); 19 var google_conversion_language = '@(googleConversionLanguage)'; 20 var google_conversion_format = '@(googleConversionFormat)'; 21 var google_conversion_color = '@(googleConversionColor)'; 22 var google_conversion_label = '@(googleConversionLabel)'; 23 var google_conversion_value = @(googleConversionValue); 24 var google_conversion_currency = '@(googleConversionCurrency)'; 25 var google_remarketing_only = @(googleRemarketingOnly ? "true" : "false"); 26 /* ]]> */ 27 </script> 28 <script type="text/javascript" src="https://www.googleadservices.com/pagead/conversion.js"></script> 29 <noscript> 30 <div style="display: inline;"> 31 <img src="https://www.googleadservices.com/pagead/conversion/@(googleConversionId)/?value=@(googleConversionValue)&amp;currency_code=@(googleConversionCurrency)&amp;label=@(googleConversionLabel)&amp;guid=ON&amp;script=0" alt="" width="1" height="1" style="border-style: none;" /> 32 </div> 33 </noscript> 34 } 35 @helper RenderGoogleAnalyticsEcommerceTracking(string transactionId, string affiliation, string revenue, string shipping, string tax, string currency, string[][] orderLines) { 36 <script type="text/javascript"> 37 if (!window.skabertrang_ga_ecommerce_callbacks) 38 window.skabertrang_ga_ecommerce_callbacks = []; 39 40 (function() { 41 var orderLines = @(Newtonsoft.Json.JsonConvert.SerializeObject(orderLines)); 42 43 window.skabertrang_ga_ecommerce_callbacks.push(function() { 44 ga('require', 'ecommerce'); 45 46 ga('ecommerce:addTransaction', { 47 'id' : '@(transactionId)', 48 'affiliation' : '@(affiliation)', 49 'revenue' : '@(revenue)', 50 'shipping' : '@(shipping)', 51 'tax' : '@(tax)', 52 'currency' : '@(currency)' 53 }); 54 55 if (orderLines && orderLines.length) { 56 for (var i = 0; i < orderLines.length; i++) { 57 ga('ecommerce:addItem', { 58 'id' : '@(transactionId)', 59 'name' : orderLines[i][1], 60 'sku' : orderLines[i][0], 61 'category' : orderLines[i][2], 62 'price' : orderLines[i][3], 63 'quantity' : orderLines[i][4], 64 'currency' : '@(currency)' 65 }); 66 } 67 } 68 69 ga('ecommerce:send'); 70 }); 71 })(); 72 </script> 73 } 74 @functions { 75 string mediaOverlay(string filePath, string filePathThumb = "", string caption = "", string group = "", string alt = "", string title = "", string extraAttributes = "") { 76 77 filePathThumb = !string.IsNullOrWhiteSpace(filePathThumb) ? filePathThumb : filePath; 78 group = !string.IsNullOrWhiteSpace(group) ? group : !string.IsNullOrWhiteSpace(GetString("ParagraphID")) ? GetString("ParagraphID") : "imageGroup"; 79 80 return "<a href='" + filePath + "' class='media-overlay' data-lightbox='" + group + "' data-title='" + caption + "'><img src='"+filePathThumb+"' alt='" + alt + "' title='" + title + "'/></a>"; 81 82 } 83 84 string GetImage(string image, int width, int height, int compression, int crop, string colorSpace, bool doNotUpscale) { 85 // Crop 86 // 0 = Center 87 // 1 = From upper left 88 // 2 = From lower left 89 // 3 = From lower right 90 // 4 = From upper right 91 // 5 = Keep aspect ratio 92 // 6 = Fit image 93 94 // ColorSpace 95 // rgb 96 // cmyk 97 // grayscale 98 99 var param = new List<string>(); 100 101 param.Add("Image=" + image); 102 param.Add("Format=" + Path.GetExtension(image).Substring(1)); 103 104 if (width > 0) { 105 param.Add("Width=" + width); 106 } 107 108 if (height > 0) { 109 param.Add("Height=" + height); 110 } 111 112 param.Add("Compression=" + compression); 113 param.Add("Crop=" + crop); 114 param.Add("ColorSpace=" + colorSpace); 115 param.Add("DoNotUpscale=" + (doNotUpscale ? "True" : "False")); 116 117 return "/Admin/Public/GetImage.ashx?" + string.Join("&amp;", param); 118 } 119 120 string GetImagePlaceholder(int width, int height) { 121 return GetImagePlaceholder(width, height, null, null, null); 122 } 123 124 string GetImagePlaceholder(int width, int height, string backgroundColor, string textColor, string text) { 125 var r = "https://placehold.it/" + width; 126 127 if (height > 0) { 128 r += "x" + height; 129 } 130 131 if (!string.IsNullOrWhiteSpace(backgroundColor) && !string.IsNullOrWhiteSpace(textColor)) { 132 r += "/" + backgroundColor; 133 r += "/" + textColor; 134 } 135 136 if (!string.IsNullOrWhiteSpace(text)) { 137 r += "?text=" + text.Replace(" ", "+"); 138 } 139 140 return r; 141 } 142 143 144 T LoadContextItem<T>(string key) { 145 var obj = HttpContext.Current.Items != null ? HttpContext.Current.Items[key] : null; 146 147 if (obj == null) { 148 return default(T); 149 } 150 151 return (T)obj; 152 } 153 154 void SaveContextItem(string key, object value) { 155 if (HttpContext.Current.Items != null && value != null) { 156 HttpContext.Current.Items[key] = value; 157 } 158 } 159 160 string PathCombine(params string[] paths) { 161 return Path.Combine(paths); 162 } 163 164 string NullIfEmpty(string value) { 165 return string.IsNullOrEmpty(value) ? null : value; 166 } 167 168 string NullIfWhiteSpace(string value) { 169 return string.IsNullOrWhiteSpace(value) ? null : value; 170 } 171 172 string ToJson(object value) { 173 return ToJson(value, false); 174 } 175 176 string ToJson(object value, bool indented) { 177 return Newtonsoft.Json.JsonConvert.SerializeObject( 178 value, 179 indented ? Newtonsoft.Json.Formatting.Indented : Newtonsoft.Json.Formatting.None, 180 new Newtonsoft.Json.Converters.IsoDateTimeConverter { DateTimeFormat = "yyyyMMdd'T'HHmmss" } 181 ); 182 } 183 184 void AddCssFile(params string[] files) { 185 var list = LoadContextItem<List<string>>("SB.CssFiles"); 186 187 if (list == null) { 188 list = new List<string>(); 189 } 190 191 foreach (var file in files) { 192 if (!list.Contains(file, StringComparer.OrdinalIgnoreCase)) { 193 list.Add(file); 194 } 195 } 196 197 SaveContextItem("SB.CssFiles", list); 198 } 199 200 void AddJsFile(params string[] files) { 201 var list = LoadContextItem<List<string>>("SB.JsFiles"); 202 203 if (list == null) { 204 list = new List<string>(); 205 } 206 207 foreach (var file in files) { 208 if (!list.Contains(file, StringComparer.OrdinalIgnoreCase)) { 209 list.Add(file); 210 } 211 } 212 213 SaveContextItem("SB.JsFiles", list); 214 } 215 } 216 @{ 217 var designBaseUrl = GetString("Template:DesignBaseUrl"); 218 219 var lockArea = new int[] { 1, 2 }; 220 var pageNews = Pageview.Page; 221 var pageNewsType = pageNews.Item.ContainsKey("Type") ? ""+pageNews.Item["Type"] : string.Empty; 222 223 while (true) { 224 pageNews = pageNews.Parent; 225 226 if (pageNews == null || pageNews.IsFolder) { 227 break; 228 } 229 230 pageNewsType = pageNews.Item.ContainsKey("Type") ? ""+pageNews.Item["Type"] : pageNewsType; 231 } 232 233 var local_News = GetLoop("ItemPublisher:Items.List") 234 .Select(o => new { 235 PageId = o.GetInteger("ItemPublisher:Item.Field.PageId"), 236 Headline = o.GetString("ItemPublisher:Item.Headline"), 237 Type = o.GetString("ItemPublisher:Item.Type"), 238 Date = o.GetDate("ItemPublisher:Item.Date"), 239 SpotImage = o.GetString("ItemPublisher:Item.SpotImage"), 240 SpotTeaserText = o.GetString("ItemPublisher:Item.SpotTeaserText"), 241 PublishToFranchise = false 242 }) 243 .Where(o => o.PageId != Pageview.Page.ID && (!string.IsNullOrWhiteSpace(pageNewsType) ? o.Type == pageNewsType : 1 == 1)) 244 .OrderByDescending(o => o.Date) 245 .ToList(); 246 247 var base_Area = Dynamicweb.Services.Areas.GetArea(2); 248 var items = new List<dynamic>(); 249 var leftItems = new List<dynamic>(); 250 int base_FolderNews = 0; 251 252 if(base_Area != null && base_Area.Item.ContainsKey("Folder_News") && int.TryParse(""+base_Area.Item["Folder_News"], out base_FolderNews) && base_FolderNews != 0){ 253 var base_NewsItems = Dynamicweb.Services.Pages.GetPagesByParentID(Dynamicweb.Services.Pages.GetPage(base_FolderNews).ID).Where(x => x.Active && x.ItemType == "News"); 254 var base_News = base_NewsItems.Select(o => new { 255 PageId = (int)o.ID, 256 Headline = "" + o.Item["Headline"], 257 Type = "" + o.ItemType, 258 Date = (DateTime)o.Item["Date"], 259 SpotImage = "" + o.Item["SpotImage"], 260 SpotTeaserText = "" + o.Item["SpotTeaserText"], 261 PublishToFranchise = (bool)o.Item["PublishToFranchise"] 262 }) 263 .Where(o => o.PublishToFranchise && (!string.IsNullOrWhiteSpace(pageNewsType) ? o.Type == pageNewsType : 1 == 1) && !lockArea.Contains(Pageview.AreaID)) 264 .OrderByDescending(o => o.Date) 265 .ToList(); 266 267 268 269 if (local_News.Count > 1 && base_News.Count > 0) { 270 items.Add(local_News[0]); 271 items.Add(local_News[1]); 272 items.Add(base_News[0]); 273 274 local_News.RemoveAt(0); 275 local_News.RemoveAt(0); 276 base_News.RemoveAt(0); 277 } else if (local_News.Count > 0 && base_News.Count > 0) { 278 items.Add(local_News[0]); 279 items.Add(base_News[0]); 280 281 local_News.RemoveAt(0); 282 base_News.RemoveAt(0); 283 } 284 leftItems.AddRange(local_News); 285 leftItems.AddRange(base_News); 286 } 287 288 289 290 291 292 items.AddRange(leftItems.OrderByDescending(o => o.Date)); 293 294 if (items.Any()) { 295 AddCssFile("https://cdnjs.cloudflare.com/ajax/libs/Swiper/3.4.2/css/swiper.min.css"); 296 AddJsFile( 297 "https://cdnjs.cloudflare.com/ajax/libs/textfit/2.3.1/textFit.min.js", 298 "https://cdnjs.cloudflare.com/ajax/libs/jQuery.dotdotdot/1.7.4/jquery.dotdotdot.min.js", 299 "https://cdnjs.cloudflare.com/ajax/libs/Swiper/3.4.2/js/swiper.jquery.min.js" 300 ); 301 } 302 } 303 @if (items.Any()) { 304 <div class="list-newss-extra"> 305 <div class="container"> 306 <div class="swiper-container-wrapper"> 307 <div class="swiper-container"> 308 <div class="swiper-wrapper"> 309 @foreach (var item in items) { 310 var spotImage = item.SpotImage; 311 312 if (string.IsNullOrWhiteSpace(spotImage)) { 313 spotImage = designBaseUrl + "img/news-bg.png"; 314 } 315 316 <div class="swiper-slide"> 317 <div class="list-news" data-newstype="@(item.Type)"> 318 <a href="/Default.aspx?Id=@(item.PageId)" class="list-news-bg"> 319 <img src="@(spotImage)" alt="" class="img-responsive"> 320 <div class="list-news-date"> 321 @(item.Date.ToString("dd.")) 322 <div>@(item.Date.ToString("MMMM yyyy"))</div> 323 </div> 324 </a> 325 <div class="list-news-content"> 326 <div class="list-news-headline hidden"> 327 @(item.Headline) 328 </div> 329 <p>@(item.SpotTeaserText)</p> 330 <a class="btn btn-type-@(item.Type)" href="/Default.aspx?Id=@(item.PageId)" role="button">@(Translate("Læs mere"))</a> 331 </div> 332 </div> 333 </div> 334 } 335 </div> 336 <div class="swiper-pagination"></div> 337 </div> 338 339 @if (items.Count > 3) { 340 <div class="swiper-button-prev"></div> 341 <div class="swiper-button-next"></div> 342 } 343 </div> 344 </div> 345 </div> 346 347 <script type="text/javascript"> 348 (function($) { 349 function resizer() { 350 var $target = $('.list-news-headline'); 351 $target.removeClass('hidden'); 352 textFit($target, { maxFontSize: 24, alignVert: true, multiLine: true }); 353 } 354 355 function ellipsis() { 356 $('> p', '.list-news-content').dotdotdot({ }); 357 } 358 359 $(window).on('load resize orientationchange', function() { 360 resizer(); 361 ellipsis(); 362 }); 363 })($); 364 365 $(function() { 366 var mySwiper = new Swiper('.list-newss-extra .swiper-container', { 367 paginationClickable: true, 368 slidesPerView: 3, 369 spaceBetween: 90, 370 breakpoints: { 371 1200 : { spaceBetween: 60 }, 372 992 : { slidesPerView: 2, spaceBetween: 30 }, 373 768 : { slidesPerView: 1 } 374 }, 375 376 @if (items.Count > 3) { 377 @: nextButton: '.list-newss-extra .swiper-button-next', 378 @: prevButton: '.list-newss-extra .swiper-button-prev', 379 } 380 381 pagination: '.list-newss-extra .swiper-pagination' 382 }); 383 }); 384 </script> 385 }