Sorry. There is nothing to view here
Error executing template "Designs/Swift/Paragraph/Swift_Logo_Custom.cshtml" System.ArgumentNullException: Value cannot be null. Parameter name: source at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate) at CompiledRazorTemplates.Dynamic.RazorEngine_faee348ae1ac42518debd2e334bab739.Execute() in E:\Solutions\dlf.test002.webtester.dk\Files\Templates\Designs\Swift\Paragraph\Swift_Logo_Custom.cshtml:line 61 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 System.IO 3 @using System.Collections.Generic 4 @using Dynamicweb.Ecommerce.ProductCatalog 5 6 @* CUSTOMIZED STANDARD SWIFT (v1.11.0) TEMPLATE *@ 7 8 @{ 9 Dynamicweb.Frontend.LinkViewModel logoLink = Model.Item.GetLink("Link"); 10 logoLink.Url = logoLink.Url == "/" && Pageview.IsVisualEditorMode ? "/Default.aspx?AreaID=" + Pageview.Area.ID : logoLink.Url; 11 12 string horizontalAlign = !string.IsNullOrEmpty(Model.Item.GetRawValueString("HorizontalAlignment")) ? "justify-content-" + Model.Item.GetRawValueString("HorizontalAlignment") : ""; 13 14 string contentPadding = Model.Item.GetRawValueString("ContentPadding", "px-3 py-2"); 15 contentPadding = contentPadding == "none" ? "p-0" : contentPadding; 16 contentPadding = contentPadding == "small" ? "px-3 py-2" : contentPadding; 17 contentPadding = contentPadding == "large" ? "px-4 py-3" : contentPadding; 18 19 string theme = !string.IsNullOrWhiteSpace(Model.Item.GetRawValueString("Theme")) ? " theme " + Model.Item.GetRawValueString("Theme").Replace(" ", "").Trim().ToLower() : ""; 20 string title = !string.IsNullOrEmpty(Model.Item.GetString("LogoName")) ? Model.Item.GetString("LogoName") : ""; 21 22 // CUSTOM 23 int logoWidthPx = Model.Item.GetInt32("LogoWidth"); 24 string logoWidth = !string.IsNullOrEmpty(Model.Item.GetString("LogoWidth")) ? "width: " + logoWidthPx + "px" : ""; 25 logoWidth = logoWidth == "width: 0px" ? "" : logoWidth; 26 27 string backgroundPaddingTop = Model.Item.GetRawValueString("Custom_BackgroundPaddingTop", "1rem"); 28 string backgroundPaddingRight = Model.Item.GetRawValueString("Custom_BackgroundPaddingRight", "3rem"); 29 string backgroundPaddingBottom = Model.Item.GetRawValueString("Custom_BackgroundPaddingBottom", "1rem"); 30 string backgroundPaddingLeft = Model.Item.GetRawValueString("Custom_BackgroundPaddingLeft", "1.5rem"); 31 string backgroundPadding = $"{backgroundPaddingTop} {backgroundPaddingRight} {backgroundPaddingBottom} {backgroundPaddingLeft}"; 32 33 string containerWidth = $"calc({logoWidthPx}px + {backgroundPaddingLeft} + 1rem)"; 34 35 36 bool productCategoryDeterminesBgColor = Model.Item.GetBoolean("Custom_ProductCategoryDeterminesBgColor"); 37 string defaultBackgroundColor = Model.Item.GetString("Custom_BackgroundColor"); 38 string backgroundColor = defaultBackgroundColor; 39 int polygonShape = Model.Item.GetInt32("Custom_PolygonShape"); 40 int yAxisTopValue; 41 42 if (!int.TryParse(Model.Item.GetRawValueString("Custom_YAxisTopValue", "60"), out yAxisTopValue)) 43 { 44 yAxisTopValue = 60; 45 } 46 47 ProductViewModel product = null; 48 ProductListViewModel productList = null; 49 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails")) 50 { 51 product = (ProductViewModel)Dynamicweb.Context.Current.Items["ProductDetails"]; 52 } 53 54 if (Dynamicweb.Context.Current.Items.Contains("ProductList")) 55 { 56 productList = (ProductListViewModel)Dynamicweb.Context.Current.Items["ProductList"]; 57 } 58 59 if (product != null) 60 { 61 var productCategory = product.ProductCategories.FirstOrDefault(pc => pc.Value.Fields != null && pc.Value.Fields.ContainsKey("ThemeColor")); 62 if (productCategory.Value?.Fields != null && productCategory.Value.Fields.ContainsKey("ThemeColor")) 63 { 64 var themeColorField = productCategory.Value.Fields["ThemeColor"]; 65 var themeColorOptions = themeColorField.Value as List<FieldOptionValueViewModel>; 66 string color = themeColorOptions?.FirstOrDefault()?.Value?.ToString() ?? ""; 67 backgroundColor = !string.IsNullOrEmpty(color) ? color : backgroundColor; 68 } 69 } 70 else if (productList != null) 71 { 72 var mostCommonColor = productList.Products 73 .Select(p => p.ProductCategories.FirstOrDefault(pc => pc.Value.Fields != null && pc.Value.Fields.ContainsKey("ThemeColor")).Value) 74 .Where(cat => cat != null) 75 .Select(cat => (cat.Fields["ThemeColor"].Value as List<FieldOptionValueViewModel>)?.FirstOrDefault()?.Value?.ToString() ?? "") 76 .Where(color => !string.IsNullOrEmpty(color)) 77 .GroupBy(color => color) 78 .OrderByDescending(g => g.Count()) 79 .Select(g => g.Key) 80 .FirstOrDefault(); 81 82 backgroundColor = !string.IsNullOrEmpty(mostCommonColor) ? mostCommonColor : backgroundColor; 83 } 84 85 bool enableCustomBackground = (productCategoryDeterminesBgColor && (product != null || productList != null)) || !string.IsNullOrEmpty(defaultBackgroundColor); 86 // 87 } 88 89 <div class="custom-logo-shape-wrapper" style="width: @containerWidth; --container-width: @containerWidth; --logo-shape-margin-top: -@(yAxisTopValue)px; --logo-padding-left: @backgroundPaddingLeft; --logo-padding-right: @backgroundPaddingRight; --logo-polygon-x-base: calc(@(containerWidth) * @(polygonShape) / 100);"> 90 <figure class="custom-logo-shape-container m-0 d-flex @(horizontalAlign)@(theme) item_@Model.Item.SystemName.ToLower()" style="clip-path: polygon(0 0, var(--logo-polygon-x, @(polygonShape)%) 0, 100% 100%, 0% 100%); padding-top: @backgroundPaddingTop; padding-bottom: @backgroundPaddingBottom; background-color: @backgroundColor;"> 91 92 @if (enableCustomBackground) 93 { 94 <div class="custom-logo-shape"> 95 @if (logoLink != null) 96 { 97 <a href="@logoLink.Url" class="text-decoration-none" aria-label="@title"> 98 @RenderLogo(logoWidth) 99 </a> 100 } 101 else 102 { 103 @RenderLogo(logoWidth) 104 } 105 </div> 106 } 107 else 108 { 109 if (logoLink != null) 110 { 111 <a href="@logoLink.Url" class="text-decoration-none" aria-label="@title"> 112 @RenderLogo(logoWidth) 113 </a> 114 } 115 else 116 { 117 @RenderLogo(logoWidth) 118 } 119 } 120 </figure> 121 </div> 122 123 @helper RenderLogo(string logoWidth) 124 { 125 string logoImage = Model?.Item?.GetFile("Image")?.Path != null ? Model.Item.GetFile("Image").Path : ""; 126 127 if (logoImage != "") 128 { 129 string title = !string.IsNullOrEmpty(Model.Item.GetString("LogoName")) ? Model.Item.GetString("LogoName") : ""; 130 131 if (Path.GetExtension(logoImage).ToLower() == ".svg") 132 { 133 <div class="icon-auto" style="@logoWidth"> 134 @ReadFile(logoImage) 135 </div> 136 } 137 else 138 { 139 int imageWidth = !string.IsNullOrEmpty(Model.Item.GetString("LogoWidth")) ? Model.Item.GetInt32("LogoWidth") : 500; 140 string imagePath = "/Admin/Public/GetImage.ashx?width=" + imageWidth + "&image=" + logoImage; 141 142 <picture class="mx-auto d-block"> 143 <img src="@logoImage" alt="@title" style="@logoWidth" /> 144 </picture> 145 } 146 } 147 else 148 { 149 string title = !string.IsNullOrEmpty(Model.Item.GetString("LogoName")) ? Model.Item.GetString("LogoName") : "Swift"; 150 <span class="fs-4">@title</span> 151 } 152 } 153