Error executing template "Designs/Swift/Navigation/OffCanvasNavigation/NavItem.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetGroupAssets(MediaViewModelSettings settings, Group group)
at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateProductGroup(ProductGroupViewModelSettings settings, ViewModelPropertyFiller`1 filler, Group group)
at Dynamicweb.Ecommerce.ProductCatalog.NavigationTreeViewNodeExtensions.GetProductGroup(NavigationTreeNodeViewModel node)
at CompiledRazorTemplates.Dynamic.RazorEngine_041355caf40a43f198a3efc910835d05.ExecuteAsync()
at RazorEngine.Templating.TemplateBase.Run(ExecuteContext context, TextWriter reader)
at RazorEngine.Templating.RazorEngineCore.RunTemplate(ICompiledTemplate template, TextWriter writer, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineService.Run(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.DynamicWrapperService.Run(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineServiceExtensions.Run(IRazorEngineService service, String name, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass23_0.<Run>b__0(TextWriter writer)
at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
at RazorEngine.Templating.RazorEngineServiceExtensions.Run(IRazorEngineService service, String name, Type modelType, Object model, DynamicViewBag viewBag)
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.Navigation.NavigationTreeNodeViewModel>
2 @using System.IO
3 @using System.Text.RegularExpressions
4 @using Dynamicweb
5 @using Dynamicweb.Ecommerce.ProductCatalog
6 @{
7 string productGroupImageShape = GetViewParameterString("ProductGroupImageShape") != null ? GetViewParameterString("ProductGroupImageShape") : string.Empty;
8 bool showProductGroupImage = GetViewParameterString("ShowProductGroupImage") != null ? GetViewParameterBoolean("ShowProductGroupImage") : false;
9 string productGroupPromotionImageTheme = GetViewParameterString("ProductGroupPromotionImageTheme") != null ? GetViewParameterString("ProductGroupPromotionImageTheme").ToLower() : string.Empty;
10 bool showProductGroupPromotionImage = GetViewParameterString("ShowProductGroupPromotionImage") != null ? GetViewParameterBoolean("ShowProductGroupPromotionImage") : false;
11
12 string ratio = GetViewParameterString("ImageAspectRatio") != null ? GetViewParameterString("ImageAspectRatio") : string.Empty;
13 ratio = ratio != "0" ? ratio : string.Empty;
14
15 var parameters = new Dictionary<string, object>();
16 parameters.Add("ProductGroupImageShape", productGroupImageShape);
17 parameters.Add("ShowProductGroupImage", showProductGroupImage);
18 parameters.Add("ProductGroupPromotionImageTheme", productGroupPromotionImageTheme);
19 parameters.Add("ShowProductGroupPromotionImage", showProductGroupPromotionImage);
20 parameters.Add("Ratio", ratio);
21
22 var page = Dynamicweb.Content.Services.Pages.GetPage(Model.PageId);
23 string pageType = page.ItemType;
24
25 var paragraphId = Pageview.CurrentParagraph.ID;
26 string groupId = Dynamicweb.Context.Current.Request["GroupID"] != null ? Dynamicweb.Context.Current.Request["GroupID"].ToString() : string.Empty;
27 string productId = Dynamicweb.Context.Current.Request["ProductID"] != null ? Dynamicweb.Context.Current.Request["ProductID"].ToString() : string.Empty;
28 string variantId = Dynamicweb.Context.Current.Request["VariantID"] != null ? Dynamicweb.Context.Current.Request["VariantID"].ToString() : string.Empty;
29
30 string productGroupImageSize = "24";
31
32 Regex reg = new Regex(@"\(([^\)]+)\)");
33
34 var navigationTree = new Stack<Dynamicweb.Frontend.Navigation.NavigationTreeNodeViewModel>(Model.Nodes);
35
36 var hasChildren = Model.Nodes.Count() > 0;
37 var nodeId = !string.IsNullOrEmpty(Model.GroupId) ? Model.GroupId : Model.PageId.ToString();
38 var inPathChecked = Model.InPath ? "checked" : string.Empty;
39 var inPathClass = Model.InPath ? " in-path" : string.Empty;
40 var activeClass = Model.IsActive ? " active fw-bold" : string.Empty;
41 }
42
43 <div class="nav-item d-flex align-items-center w-100 py-1">
44 @if (pageType != "Swift_Preferences")
45 {
46 var group = Model.GetProductGroup();
47 IList<FieldValueViewModel> groupFields = group.GroupFields != null ? group.GroupFields : null;
48
49 if (Model.IsClickable)
50 {
51 <a class="nav-link position-relative d-flex align-items-center gap-2 flex-grow-1@(activeClass)@(inPathClass)" @(Model.IsActive ? "aria-current='page'" : string.Empty) href="@Model.Link" id="@nodeId">
52 @if (showProductGroupImage && !string.IsNullOrEmpty(Model.GroupId) && groupFields != null)
53 {
54 foreach (FieldValueViewModel field in groupFields)
55 {
56 if (field.SystemName == "ProductGroupNavigationImage" && !string.IsNullOrEmpty(field.Value.ToString()))
57 {
58 var groupImage = field.Value.ToString();
59
60 if (Path.GetExtension(groupImage).ToLower() == ".svg")
61 {
62 <span class="icon-auto @productGroupImageShape" style="height: @(productGroupImageSize)px; width: @(productGroupImageSize)px;">
63 @ReadFile("/Files/Images/" + groupImage)
64 </span>
65 }
66 else
67 {
68 var imagePath = "/Admin/Public/GetImage.ashx?Image=" + "/Files/Images/" + Dynamicweb.Context.Current.Server.UrlEncode(groupImage) + "&Width=" + productGroupImageSize + "&Height=" + productGroupImageSize + "&crop=0";
69 <img loading="lazy" class="@productGroupImageShape" alt="@group.Name" width="@productGroupImageSize" height="@productGroupImageSize" src="@imagePath">
70 }
71 }
72 }
73 }
74 <span class="flex-grow-1">
75 @Model.Name
76 </span>
77 </a>
78
79 if (hasChildren)
80 {
81 <label class="nav-link position-relative" role="button" tabindex="0" aria-label="Unfold @Model.Name" for="nav_@(paragraphId)_@(nodeId)">
82 @{
83 string iconPath = "/Files/Templates/Designs/Swift/Assets/icons/arrow-right.svg";
84 if (!iconPath.ToLower().Contains("none") && iconPath != string.Empty)
85 {
86 iconPath = Dynamicweb.Context.Current.Server.MapPath(iconPath);
87 <span class="icon-3">@ReadFile(iconPath)</span>
88 }
89 }
90 </label>
91 }
92 }
93 else
94 {
95 <label class="nav-link position-relative d-flex align-items-center gap-2 flex-grow-1@(activeClass)@(inPathClass)" role="button" tabindex="0" @(Model.IsActive ? "aria-current='page'" : "") aria-label="Unfold @Model.Name" for="nav_@(paragraphId)_@(nodeId)">
96 @if (showProductGroupImage && !string.IsNullOrEmpty(Model.GroupId) && groupFields != null)
97 {
98 foreach (FieldValueViewModel field in groupFields)
99 {
100 if (field.SystemName == "ProductGroupNavigationImage" && !string.IsNullOrEmpty(field.Value.ToString()))
101 {
102 var groupImage = field.Value.ToString();
103
104 if (Path.GetExtension(groupImage).ToLower() == ".svg")
105 {
106 <span class="icon-auto @productGroupImageShape" style="height: @(productGroupImageSize)px; width: @(productGroupImageSize)px;">
107 @ReadFile("/Files/Images/" + groupImage)
108 </span>
109 }
110 else
111 {
112 var imagePath = "/Admin/Public/GetImage.ashx?Image=" + "/Files/Images/" + Dynamicweb.Context.Current.Server.UrlEncode(groupImage) + "&Width=" + productGroupImageSize + "&Height=" + productGroupImageSize + "&crop=0";
113 <img loading="lazy" class="@productGroupImageShape" alt="@group.Name" width="@productGroupImageSize" height="@productGroupImageSize" src="@imagePath">
114 }
115 }
116 }
117 }
118
119 <span class="flex-grow-1">
120 @Model.Name
121 </span>
122
123 @if (hasChildren)
124 {
125 string iconPath = "/Files/Templates/Designs/Swift/Assets/icons/arrow-right.svg";
126 if (!iconPath.ToLower().Contains("none") && iconPath != string.Empty)
127 {
128 iconPath = Dynamicweb.Context.Current.Server.MapPath(iconPath);
129 <span class="icon-3">@ReadFile(iconPath)</span>
130 }
131 }
132 </label>
133 }
134
135 if (hasChildren)
136 {
137 <input type="checkbox" class="visually-hidden sub-nav-check" id="nav_@(paragraphId)_@(nodeId)" @inPathChecked>
138 <div class="nav sub-nav position-absolute h-100 opacity-0 pe-none invisible w-100 left-0 top-0">
139 <div class="h-100 w-100 overflow-y-auto overflow-x-hidden">
140 <div class="nav-header position-relative py-1">
141 <label class="nav-link position-relative d-flex align-items-center gap-2 flex-grow-1" role="button" tabindex="0" aria-label="Go back to @Model.Name" for="nav_@(paragraphId)_@(nodeId)">
142 @{
143 string iconPath = "/Files/Templates/Designs/Swift/Assets/icons/arrow-left.svg";
144 if (!iconPath.ToLower().Contains("none") && iconPath != string.Empty)
145 {
146 iconPath = Dynamicweb.Context.Current.Server.MapPath(iconPath);
147 <span class="icon-3">@ReadFile(iconPath)</span>
148 }
149 }
150 <span class="flex-grow-1">@Model.Name</span>
151 </label>
152 </div>
153
154 @foreach (var node in Model.Nodes)
155 {
156 @RenderPartial("Navigation/OffCanvasNavigation/NavItem.cshtml", node, parameters)
157 }
158
159 @if (groupFields != null)
160 {
161 var groupName = group.Name;
162 string ratioCssClass = ratio != string.Empty ? " ratio" : string.Empty;
163 string ratioVariable = ratio != string.Empty ? "style=\"--bs-aspect-ratio: " + ratio + "\"" : string.Empty;
164 string productGroupPromotionImage = string.Empty;
165 string productGroupPromotionImagePath = string.Empty;
166 string productGroupPromotionDescription = string.Empty;
167 string productGroupPromotionLinkLabel = string.Empty;
168 string productGroupPromotionLink = string.Empty;
169 string gridGap = !string.IsNullOrEmpty(productGroupPromotionImageTheme) ? "gap-0" : "gap-3";
170 string themePadding = !string.IsNullOrEmpty(productGroupPromotionImageTheme) ? "p-3" : "p-0";
171
172 foreach (FieldValueViewModel field in groupFields)
173 {
174 if (field.SystemName == "ProductGroupPromotionImage")
175 {
176 productGroupPromotionImage = field.Value != null ? field.Value.ToString() : string.Empty;
177 productGroupPromotionImagePath = "/Admin/Public/GetImage.ashx?Width=" + 480 + "&crop=0&image=" + "Files/Images/" + productGroupPromotionImage;
178 }
179 if (field.SystemName == "ProductGroupPromotionDescription")
180 {
181 productGroupPromotionDescription = field.Value != null ? field.Value.ToString() : string.Empty;
182 }
183 if (field.SystemName == "ProductGroupPromotionLinkLabel")
184 {
185 productGroupPromotionLinkLabel = field.Value != null ? field.Value.ToString() : string.Empty;
186 }
187 if (field.SystemName == "ProductGroupPromotionLink")
188 {
189 productGroupPromotionLink = field.Value != null ? field.Value.ToString() : string.Empty;
190 }
191 }
192 if (showProductGroupPromotionImage)
193 {
194 <div class="grid grid-1 mt-3 mx-3 @gridGap@(productGroupPromotionImageTheme)">
195 @if (productGroupPromotionImage != string.Empty)
196 {
197 productGroupPromotionLink = !string.IsNullOrEmpty(productGroupPromotionLink) ? productGroupPromotionLink : Model.Link;
198
199 <a href="@productGroupPromotionLink" title="@groupName">
200 <figure class="m-0@(ratioCssClass)" @ratioVariable>
201 <img class="img-fluid" src="@productGroupPromotionImagePath" alt="@groupName" style="object-fit:cover">
202 </figure>
203 </a>
204 }
205 @if (!string.IsNullOrEmpty(productGroupPromotionDescription) || !string.IsNullOrEmpty(productGroupPromotionLinkLabel))
206 {
207 <div class="grid grid-1 @themePadding ">
208
209 @if (!string.IsNullOrEmpty(productGroupPromotionDescription))
210 {
211 <h6 class="m-0">@productGroupPromotionDescription</h6>
212 }
213 @if (!string.IsNullOrEmpty(productGroupPromotionLinkLabel))
214 {
215 productGroupPromotionLink = !string.IsNullOrEmpty(productGroupPromotionLink) ? productGroupPromotionLink : Model.Link;
216
217 <a href="@productGroupPromotionLink" title="@productGroupPromotionLinkLabel" class="btn btn-link text-start border-0 p-0">@productGroupPromotionLinkLabel</a>
218 }
219 </div>
220 }
221 </div>
222 }
223 }
224 </div>
225 </div>
226 }
227 }
228 else
229 {
230 bool countrySelector = page.Item?["CountrySelector"] != null ? Convert.ToBoolean(page.Item["CountrySelector"].ToString()) : false;
231 bool languageSelector = page.Item?["LanguageSelector"] != null ? Convert.ToBoolean(page.Item["LanguageSelector"].ToString()) : false;
232 bool currencySelector = page.Item?["CurrencySelector"] != null ? Convert.ToBoolean(page.Item["CurrencySelector"].ToString()) : false;
233 string name = Translate("Preferences");
234 string icon = string.Empty;
235
236 if (languageSelector)
237 {
238 bool hideIcon = page.Item?["HideIcon"] != null ? Convert.ToBoolean(page.Item["HideIcon"].ToString()) : false;
239
240 if (!hideIcon)
241 {
242 icon = $"/Files/FlagIcons/{Pageview.Area.CultureInfo.Name.ToLower()}.svg";
243 }
244
245 name = reg.Replace(Pageview.Area.CultureInfo.DisplayName, string.Empty);
246 }
247
248 <form action="/Default.aspx?ID=@Model.PageId" data-response-target-element="PreferencesModalContent" data-layout-template="Swift_Preferences.cshtml" data-preloader="inline" class="w-100">
249 <input type="hidden" name="Layout" value="modal">
250 <input type="hidden" name="CurrentPageID" value="@Pageview.ID">
251 <input type="hidden" name="GroupID" value="@groupId">
252 <input type="hidden" name="ProductID" value="@productId">
253 <input type="hidden" name="VariantID" value="@variantId">
254 <a href="#" role="button" onclick="swift.PageUpdater.Update(event)" class="nav-link position-relative flex-fill swift_open-preferences-modal @activeClass @inPathClass" @(Model.IsActive ? "aria-current='page'" : "") data-bs-toggle="modal" data-bs-target="#PreferencesModal">
255 @if (icon != "")
256 {
257 if (Path.GetExtension(icon).ToLower() == ".svg" && !icon.ToLower().Contains("none"))
258 {
259 string iconPath = Dynamicweb.Context.Current.Server.MapPath(icon);
260
261 <span class="icon-2">@ReadFile(iconPath)</span>
262 }
263 }
264 <span>@name</span>
265 </a>
266 </form>
267 }
268 </div>
269
Error executing template "Designs/Swift/Navigation/OffCanvasNavigation/NavItem.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetGroupAssets(MediaViewModelSettings settings, Group group)
at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateProductGroup(ProductGroupViewModelSettings settings, ViewModelPropertyFiller`1 filler, Group group)
at Dynamicweb.Ecommerce.ProductCatalog.NavigationTreeViewNodeExtensions.GetProductGroup(NavigationTreeNodeViewModel node)
at CompiledRazorTemplates.Dynamic.RazorEngine_041355caf40a43f198a3efc910835d05.ExecuteAsync()
at RazorEngine.Templating.TemplateBase.Run(ExecuteContext context, TextWriter reader)
at RazorEngine.Templating.RazorEngineCore.RunTemplate(ICompiledTemplate template, TextWriter writer, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineService.Run(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.DynamicWrapperService.Run(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineServiceExtensions.Run(IRazorEngineService service, String name, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass23_0.<Run>b__0(TextWriter writer)
at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
at RazorEngine.Templating.RazorEngineServiceExtensions.Run(IRazorEngineService service, String name, Type modelType, Object model, DynamicViewBag viewBag)
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.Navigation.NavigationTreeNodeViewModel>
2 @using System.IO
3 @using System.Text.RegularExpressions
4 @using Dynamicweb
5 @using Dynamicweb.Ecommerce.ProductCatalog
6 @{
7 string productGroupImageShape = GetViewParameterString("ProductGroupImageShape") != null ? GetViewParameterString("ProductGroupImageShape") : string.Empty;
8 bool showProductGroupImage = GetViewParameterString("ShowProductGroupImage") != null ? GetViewParameterBoolean("ShowProductGroupImage") : false;
9 string productGroupPromotionImageTheme = GetViewParameterString("ProductGroupPromotionImageTheme") != null ? GetViewParameterString("ProductGroupPromotionImageTheme").ToLower() : string.Empty;
10 bool showProductGroupPromotionImage = GetViewParameterString("ShowProductGroupPromotionImage") != null ? GetViewParameterBoolean("ShowProductGroupPromotionImage") : false;
11
12 string ratio = GetViewParameterString("ImageAspectRatio") != null ? GetViewParameterString("ImageAspectRatio") : string.Empty;
13 ratio = ratio != "0" ? ratio : string.Empty;
14
15 var parameters = new Dictionary<string, object>();
16 parameters.Add("ProductGroupImageShape", productGroupImageShape);
17 parameters.Add("ShowProductGroupImage", showProductGroupImage);
18 parameters.Add("ProductGroupPromotionImageTheme", productGroupPromotionImageTheme);
19 parameters.Add("ShowProductGroupPromotionImage", showProductGroupPromotionImage);
20 parameters.Add("Ratio", ratio);
21
22 var page = Dynamicweb.Content.Services.Pages.GetPage(Model.PageId);
23 string pageType = page.ItemType;
24
25 var paragraphId = Pageview.CurrentParagraph.ID;
26 string groupId = Dynamicweb.Context.Current.Request["GroupID"] != null ? Dynamicweb.Context.Current.Request["GroupID"].ToString() : string.Empty;
27 string productId = Dynamicweb.Context.Current.Request["ProductID"] != null ? Dynamicweb.Context.Current.Request["ProductID"].ToString() : string.Empty;
28 string variantId = Dynamicweb.Context.Current.Request["VariantID"] != null ? Dynamicweb.Context.Current.Request["VariantID"].ToString() : string.Empty;
29
30 string productGroupImageSize = "24";
31
32 Regex reg = new Regex(@"\(([^\)]+)\)");
33
34 var navigationTree = new Stack<Dynamicweb.Frontend.Navigation.NavigationTreeNodeViewModel>(Model.Nodes);
35
36 var hasChildren = Model.Nodes.Count() > 0;
37 var nodeId = !string.IsNullOrEmpty(Model.GroupId) ? Model.GroupId : Model.PageId.ToString();
38 var inPathChecked = Model.InPath ? "checked" : string.Empty;
39 var inPathClass = Model.InPath ? " in-path" : string.Empty;
40 var activeClass = Model.IsActive ? " active fw-bold" : string.Empty;
41 }
42
43 <div class="nav-item d-flex align-items-center w-100 py-1">
44 @if (pageType != "Swift_Preferences")
45 {
46 var group = Model.GetProductGroup();
47 IList<FieldValueViewModel> groupFields = group.GroupFields != null ? group.GroupFields : null;
48
49 if (Model.IsClickable)
50 {
51 <a class="nav-link position-relative d-flex align-items-center gap-2 flex-grow-1@(activeClass)@(inPathClass)" @(Model.IsActive ? "aria-current='page'" : string.Empty) href="@Model.Link" id="@nodeId">
52 @if (showProductGroupImage && !string.IsNullOrEmpty(Model.GroupId) && groupFields != null)
53 {
54 foreach (FieldValueViewModel field in groupFields)
55 {
56 if (field.SystemName == "ProductGroupNavigationImage" && !string.IsNullOrEmpty(field.Value.ToString()))
57 {
58 var groupImage = field.Value.ToString();
59
60 if (Path.GetExtension(groupImage).ToLower() == ".svg")
61 {
62 <span class="icon-auto @productGroupImageShape" style="height: @(productGroupImageSize)px; width: @(productGroupImageSize)px;">
63 @ReadFile("/Files/Images/" + groupImage)
64 </span>
65 }
66 else
67 {
68 var imagePath = "/Admin/Public/GetImage.ashx?Image=" + "/Files/Images/" + Dynamicweb.Context.Current.Server.UrlEncode(groupImage) + "&Width=" + productGroupImageSize + "&Height=" + productGroupImageSize + "&crop=0";
69 <img loading="lazy" class="@productGroupImageShape" alt="@group.Name" width="@productGroupImageSize" height="@productGroupImageSize" src="@imagePath">
70 }
71 }
72 }
73 }
74 <span class="flex-grow-1">
75 @Model.Name
76 </span>
77 </a>
78
79 if (hasChildren)
80 {
81 <label class="nav-link position-relative" role="button" tabindex="0" aria-label="Unfold @Model.Name" for="nav_@(paragraphId)_@(nodeId)">
82 @{
83 string iconPath = "/Files/Templates/Designs/Swift/Assets/icons/arrow-right.svg";
84 if (!iconPath.ToLower().Contains("none") && iconPath != string.Empty)
85 {
86 iconPath = Dynamicweb.Context.Current.Server.MapPath(iconPath);
87 <span class="icon-3">@ReadFile(iconPath)</span>
88 }
89 }
90 </label>
91 }
92 }
93 else
94 {
95 <label class="nav-link position-relative d-flex align-items-center gap-2 flex-grow-1@(activeClass)@(inPathClass)" role="button" tabindex="0" @(Model.IsActive ? "aria-current='page'" : "") aria-label="Unfold @Model.Name" for="nav_@(paragraphId)_@(nodeId)">
96 @if (showProductGroupImage && !string.IsNullOrEmpty(Model.GroupId) && groupFields != null)
97 {
98 foreach (FieldValueViewModel field in groupFields)
99 {
100 if (field.SystemName == "ProductGroupNavigationImage" && !string.IsNullOrEmpty(field.Value.ToString()))
101 {
102 var groupImage = field.Value.ToString();
103
104 if (Path.GetExtension(groupImage).ToLower() == ".svg")
105 {
106 <span class="icon-auto @productGroupImageShape" style="height: @(productGroupImageSize)px; width: @(productGroupImageSize)px;">
107 @ReadFile("/Files/Images/" + groupImage)
108 </span>
109 }
110 else
111 {
112 var imagePath = "/Admin/Public/GetImage.ashx?Image=" + "/Files/Images/" + Dynamicweb.Context.Current.Server.UrlEncode(groupImage) + "&Width=" + productGroupImageSize + "&Height=" + productGroupImageSize + "&crop=0";
113 <img loading="lazy" class="@productGroupImageShape" alt="@group.Name" width="@productGroupImageSize" height="@productGroupImageSize" src="@imagePath">
114 }
115 }
116 }
117 }
118
119 <span class="flex-grow-1">
120 @Model.Name
121 </span>
122
123 @if (hasChildren)
124 {
125 string iconPath = "/Files/Templates/Designs/Swift/Assets/icons/arrow-right.svg";
126 if (!iconPath.ToLower().Contains("none") && iconPath != string.Empty)
127 {
128 iconPath = Dynamicweb.Context.Current.Server.MapPath(iconPath);
129 <span class="icon-3">@ReadFile(iconPath)</span>
130 }
131 }
132 </label>
133 }
134
135 if (hasChildren)
136 {
137 <input type="checkbox" class="visually-hidden sub-nav-check" id="nav_@(paragraphId)_@(nodeId)" @inPathChecked>
138 <div class="nav sub-nav position-absolute h-100 opacity-0 pe-none invisible w-100 left-0 top-0">
139 <div class="h-100 w-100 overflow-y-auto overflow-x-hidden">
140 <div class="nav-header position-relative py-1">
141 <label class="nav-link position-relative d-flex align-items-center gap-2 flex-grow-1" role="button" tabindex="0" aria-label="Go back to @Model.Name" for="nav_@(paragraphId)_@(nodeId)">
142 @{
143 string iconPath = "/Files/Templates/Designs/Swift/Assets/icons/arrow-left.svg";
144 if (!iconPath.ToLower().Contains("none") && iconPath != string.Empty)
145 {
146 iconPath = Dynamicweb.Context.Current.Server.MapPath(iconPath);
147 <span class="icon-3">@ReadFile(iconPath)</span>
148 }
149 }
150 <span class="flex-grow-1">@Model.Name</span>
151 </label>
152 </div>
153
154 @foreach (var node in Model.Nodes)
155 {
156 @RenderPartial("Navigation/OffCanvasNavigation/NavItem.cshtml", node, parameters)
157 }
158
159 @if (groupFields != null)
160 {
161 var groupName = group.Name;
162 string ratioCssClass = ratio != string.Empty ? " ratio" : string.Empty;
163 string ratioVariable = ratio != string.Empty ? "style=\"--bs-aspect-ratio: " + ratio + "\"" : string.Empty;
164 string productGroupPromotionImage = string.Empty;
165 string productGroupPromotionImagePath = string.Empty;
166 string productGroupPromotionDescription = string.Empty;
167 string productGroupPromotionLinkLabel = string.Empty;
168 string productGroupPromotionLink = string.Empty;
169 string gridGap = !string.IsNullOrEmpty(productGroupPromotionImageTheme) ? "gap-0" : "gap-3";
170 string themePadding = !string.IsNullOrEmpty(productGroupPromotionImageTheme) ? "p-3" : "p-0";
171
172 foreach (FieldValueViewModel field in groupFields)
173 {
174 if (field.SystemName == "ProductGroupPromotionImage")
175 {
176 productGroupPromotionImage = field.Value != null ? field.Value.ToString() : string.Empty;
177 productGroupPromotionImagePath = "/Admin/Public/GetImage.ashx?Width=" + 480 + "&crop=0&image=" + "Files/Images/" + productGroupPromotionImage;
178 }
179 if (field.SystemName == "ProductGroupPromotionDescription")
180 {
181 productGroupPromotionDescription = field.Value != null ? field.Value.ToString() : string.Empty;
182 }
183 if (field.SystemName == "ProductGroupPromotionLinkLabel")
184 {
185 productGroupPromotionLinkLabel = field.Value != null ? field.Value.ToString() : string.Empty;
186 }
187 if (field.SystemName == "ProductGroupPromotionLink")
188 {
189 productGroupPromotionLink = field.Value != null ? field.Value.ToString() : string.Empty;
190 }
191 }
192 if (showProductGroupPromotionImage)
193 {
194 <div class="grid grid-1 mt-3 mx-3 @gridGap@(productGroupPromotionImageTheme)">
195 @if (productGroupPromotionImage != string.Empty)
196 {
197 productGroupPromotionLink = !string.IsNullOrEmpty(productGroupPromotionLink) ? productGroupPromotionLink : Model.Link;
198
199 <a href="@productGroupPromotionLink" title="@groupName">
200 <figure class="m-0@(ratioCssClass)" @ratioVariable>
201 <img class="img-fluid" src="@productGroupPromotionImagePath" alt="@groupName" style="object-fit:cover">
202 </figure>
203 </a>
204 }
205 @if (!string.IsNullOrEmpty(productGroupPromotionDescription) || !string.IsNullOrEmpty(productGroupPromotionLinkLabel))
206 {
207 <div class="grid grid-1 @themePadding ">
208
209 @if (!string.IsNullOrEmpty(productGroupPromotionDescription))
210 {
211 <h6 class="m-0">@productGroupPromotionDescription</h6>
212 }
213 @if (!string.IsNullOrEmpty(productGroupPromotionLinkLabel))
214 {
215 productGroupPromotionLink = !string.IsNullOrEmpty(productGroupPromotionLink) ? productGroupPromotionLink : Model.Link;
216
217 <a href="@productGroupPromotionLink" title="@productGroupPromotionLinkLabel" class="btn btn-link text-start border-0 p-0">@productGroupPromotionLinkLabel</a>
218 }
219 </div>
220 }
221 </div>
222 }
223 }
224 </div>
225 </div>
226 }
227 }
228 else
229 {
230 bool countrySelector = page.Item?["CountrySelector"] != null ? Convert.ToBoolean(page.Item["CountrySelector"].ToString()) : false;
231 bool languageSelector = page.Item?["LanguageSelector"] != null ? Convert.ToBoolean(page.Item["LanguageSelector"].ToString()) : false;
232 bool currencySelector = page.Item?["CurrencySelector"] != null ? Convert.ToBoolean(page.Item["CurrencySelector"].ToString()) : false;
233 string name = Translate("Preferences");
234 string icon = string.Empty;
235
236 if (languageSelector)
237 {
238 bool hideIcon = page.Item?["HideIcon"] != null ? Convert.ToBoolean(page.Item["HideIcon"].ToString()) : false;
239
240 if (!hideIcon)
241 {
242 icon = $"/Files/FlagIcons/{Pageview.Area.CultureInfo.Name.ToLower()}.svg";
243 }
244
245 name = reg.Replace(Pageview.Area.CultureInfo.DisplayName, string.Empty);
246 }
247
248 <form action="/Default.aspx?ID=@Model.PageId" data-response-target-element="PreferencesModalContent" data-layout-template="Swift_Preferences.cshtml" data-preloader="inline" class="w-100">
249 <input type="hidden" name="Layout" value="modal">
250 <input type="hidden" name="CurrentPageID" value="@Pageview.ID">
251 <input type="hidden" name="GroupID" value="@groupId">
252 <input type="hidden" name="ProductID" value="@productId">
253 <input type="hidden" name="VariantID" value="@variantId">
254 <a href="#" role="button" onclick="swift.PageUpdater.Update(event)" class="nav-link position-relative flex-fill swift_open-preferences-modal @activeClass @inPathClass" @(Model.IsActive ? "aria-current='page'" : "") data-bs-toggle="modal" data-bs-target="#PreferencesModal">
255 @if (icon != "")
256 {
257 if (Path.GetExtension(icon).ToLower() == ".svg" && !icon.ToLower().Contains("none"))
258 {
259 string iconPath = Dynamicweb.Context.Current.Server.MapPath(icon);
260
261 <span class="icon-2">@ReadFile(iconPath)</span>
262 }
263 }
264 <span>@name</span>
265 </a>
266 </form>
267 }
268 </div>
269
Error executing template "Designs/Swift/Navigation/OffCanvasNavigation/NavItem.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetGroupAssets(MediaViewModelSettings settings, Group group)
at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateProductGroup(ProductGroupViewModelSettings settings, ViewModelPropertyFiller`1 filler, Group group)
at Dynamicweb.Ecommerce.ProductCatalog.NavigationTreeViewNodeExtensions.GetProductGroup(NavigationTreeNodeViewModel node)
at CompiledRazorTemplates.Dynamic.RazorEngine_041355caf40a43f198a3efc910835d05.ExecuteAsync()
at RazorEngine.Templating.TemplateBase.Run(ExecuteContext context, TextWriter reader)
at RazorEngine.Templating.RazorEngineCore.RunTemplate(ICompiledTemplate template, TextWriter writer, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineService.Run(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.DynamicWrapperService.Run(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineServiceExtensions.Run(IRazorEngineService service, String name, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass23_0.<Run>b__0(TextWriter writer)
at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
at RazorEngine.Templating.RazorEngineServiceExtensions.Run(IRazorEngineService service, String name, Type modelType, Object model, DynamicViewBag viewBag)
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.Navigation.NavigationTreeNodeViewModel>
2 @using System.IO
3 @using System.Text.RegularExpressions
4 @using Dynamicweb
5 @using Dynamicweb.Ecommerce.ProductCatalog
6 @{
7 string productGroupImageShape = GetViewParameterString("ProductGroupImageShape") != null ? GetViewParameterString("ProductGroupImageShape") : string.Empty;
8 bool showProductGroupImage = GetViewParameterString("ShowProductGroupImage") != null ? GetViewParameterBoolean("ShowProductGroupImage") : false;
9 string productGroupPromotionImageTheme = GetViewParameterString("ProductGroupPromotionImageTheme") != null ? GetViewParameterString("ProductGroupPromotionImageTheme").ToLower() : string.Empty;
10 bool showProductGroupPromotionImage = GetViewParameterString("ShowProductGroupPromotionImage") != null ? GetViewParameterBoolean("ShowProductGroupPromotionImage") : false;
11
12 string ratio = GetViewParameterString("ImageAspectRatio") != null ? GetViewParameterString("ImageAspectRatio") : string.Empty;
13 ratio = ratio != "0" ? ratio : string.Empty;
14
15 var parameters = new Dictionary<string, object>();
16 parameters.Add("ProductGroupImageShape", productGroupImageShape);
17 parameters.Add("ShowProductGroupImage", showProductGroupImage);
18 parameters.Add("ProductGroupPromotionImageTheme", productGroupPromotionImageTheme);
19 parameters.Add("ShowProductGroupPromotionImage", showProductGroupPromotionImage);
20 parameters.Add("Ratio", ratio);
21
22 var page = Dynamicweb.Content.Services.Pages.GetPage(Model.PageId);
23 string pageType = page.ItemType;
24
25 var paragraphId = Pageview.CurrentParagraph.ID;
26 string groupId = Dynamicweb.Context.Current.Request["GroupID"] != null ? Dynamicweb.Context.Current.Request["GroupID"].ToString() : string.Empty;
27 string productId = Dynamicweb.Context.Current.Request["ProductID"] != null ? Dynamicweb.Context.Current.Request["ProductID"].ToString() : string.Empty;
28 string variantId = Dynamicweb.Context.Current.Request["VariantID"] != null ? Dynamicweb.Context.Current.Request["VariantID"].ToString() : string.Empty;
29
30 string productGroupImageSize = "24";
31
32 Regex reg = new Regex(@"\(([^\)]+)\)");
33
34 var navigationTree = new Stack<Dynamicweb.Frontend.Navigation.NavigationTreeNodeViewModel>(Model.Nodes);
35
36 var hasChildren = Model.Nodes.Count() > 0;
37 var nodeId = !string.IsNullOrEmpty(Model.GroupId) ? Model.GroupId : Model.PageId.ToString();
38 var inPathChecked = Model.InPath ? "checked" : string.Empty;
39 var inPathClass = Model.InPath ? " in-path" : string.Empty;
40 var activeClass = Model.IsActive ? " active fw-bold" : string.Empty;
41 }
42
43 <div class="nav-item d-flex align-items-center w-100 py-1">
44 @if (pageType != "Swift_Preferences")
45 {
46 var group = Model.GetProductGroup();
47 IList<FieldValueViewModel> groupFields = group.GroupFields != null ? group.GroupFields : null;
48
49 if (Model.IsClickable)
50 {
51 <a class="nav-link position-relative d-flex align-items-center gap-2 flex-grow-1@(activeClass)@(inPathClass)" @(Model.IsActive ? "aria-current='page'" : string.Empty) href="@Model.Link" id="@nodeId">
52 @if (showProductGroupImage && !string.IsNullOrEmpty(Model.GroupId) && groupFields != null)
53 {
54 foreach (FieldValueViewModel field in groupFields)
55 {
56 if (field.SystemName == "ProductGroupNavigationImage" && !string.IsNullOrEmpty(field.Value.ToString()))
57 {
58 var groupImage = field.Value.ToString();
59
60 if (Path.GetExtension(groupImage).ToLower() == ".svg")
61 {
62 <span class="icon-auto @productGroupImageShape" style="height: @(productGroupImageSize)px; width: @(productGroupImageSize)px;">
63 @ReadFile("/Files/Images/" + groupImage)
64 </span>
65 }
66 else
67 {
68 var imagePath = "/Admin/Public/GetImage.ashx?Image=" + "/Files/Images/" + Dynamicweb.Context.Current.Server.UrlEncode(groupImage) + "&Width=" + productGroupImageSize + "&Height=" + productGroupImageSize + "&crop=0";
69 <img loading="lazy" class="@productGroupImageShape" alt="@group.Name" width="@productGroupImageSize" height="@productGroupImageSize" src="@imagePath">
70 }
71 }
72 }
73 }
74 <span class="flex-grow-1">
75 @Model.Name
76 </span>
77 </a>
78
79 if (hasChildren)
80 {
81 <label class="nav-link position-relative" role="button" tabindex="0" aria-label="Unfold @Model.Name" for="nav_@(paragraphId)_@(nodeId)">
82 @{
83 string iconPath = "/Files/Templates/Designs/Swift/Assets/icons/arrow-right.svg";
84 if (!iconPath.ToLower().Contains("none") && iconPath != string.Empty)
85 {
86 iconPath = Dynamicweb.Context.Current.Server.MapPath(iconPath);
87 <span class="icon-3">@ReadFile(iconPath)</span>
88 }
89 }
90 </label>
91 }
92 }
93 else
94 {
95 <label class="nav-link position-relative d-flex align-items-center gap-2 flex-grow-1@(activeClass)@(inPathClass)" role="button" tabindex="0" @(Model.IsActive ? "aria-current='page'" : "") aria-label="Unfold @Model.Name" for="nav_@(paragraphId)_@(nodeId)">
96 @if (showProductGroupImage && !string.IsNullOrEmpty(Model.GroupId) && groupFields != null)
97 {
98 foreach (FieldValueViewModel field in groupFields)
99 {
100 if (field.SystemName == "ProductGroupNavigationImage" && !string.IsNullOrEmpty(field.Value.ToString()))
101 {
102 var groupImage = field.Value.ToString();
103
104 if (Path.GetExtension(groupImage).ToLower() == ".svg")
105 {
106 <span class="icon-auto @productGroupImageShape" style="height: @(productGroupImageSize)px; width: @(productGroupImageSize)px;">
107 @ReadFile("/Files/Images/" + groupImage)
108 </span>
109 }
110 else
111 {
112 var imagePath = "/Admin/Public/GetImage.ashx?Image=" + "/Files/Images/" + Dynamicweb.Context.Current.Server.UrlEncode(groupImage) + "&Width=" + productGroupImageSize + "&Height=" + productGroupImageSize + "&crop=0";
113 <img loading="lazy" class="@productGroupImageShape" alt="@group.Name" width="@productGroupImageSize" height="@productGroupImageSize" src="@imagePath">
114 }
115 }
116 }
117 }
118
119 <span class="flex-grow-1">
120 @Model.Name
121 </span>
122
123 @if (hasChildren)
124 {
125 string iconPath = "/Files/Templates/Designs/Swift/Assets/icons/arrow-right.svg";
126 if (!iconPath.ToLower().Contains("none") && iconPath != string.Empty)
127 {
128 iconPath = Dynamicweb.Context.Current.Server.MapPath(iconPath);
129 <span class="icon-3">@ReadFile(iconPath)</span>
130 }
131 }
132 </label>
133 }
134
135 if (hasChildren)
136 {
137 <input type="checkbox" class="visually-hidden sub-nav-check" id="nav_@(paragraphId)_@(nodeId)" @inPathChecked>
138 <div class="nav sub-nav position-absolute h-100 opacity-0 pe-none invisible w-100 left-0 top-0">
139 <div class="h-100 w-100 overflow-y-auto overflow-x-hidden">
140 <div class="nav-header position-relative py-1">
141 <label class="nav-link position-relative d-flex align-items-center gap-2 flex-grow-1" role="button" tabindex="0" aria-label="Go back to @Model.Name" for="nav_@(paragraphId)_@(nodeId)">
142 @{
143 string iconPath = "/Files/Templates/Designs/Swift/Assets/icons/arrow-left.svg";
144 if (!iconPath.ToLower().Contains("none") && iconPath != string.Empty)
145 {
146 iconPath = Dynamicweb.Context.Current.Server.MapPath(iconPath);
147 <span class="icon-3">@ReadFile(iconPath)</span>
148 }
149 }
150 <span class="flex-grow-1">@Model.Name</span>
151 </label>
152 </div>
153
154 @foreach (var node in Model.Nodes)
155 {
156 @RenderPartial("Navigation/OffCanvasNavigation/NavItem.cshtml", node, parameters)
157 }
158
159 @if (groupFields != null)
160 {
161 var groupName = group.Name;
162 string ratioCssClass = ratio != string.Empty ? " ratio" : string.Empty;
163 string ratioVariable = ratio != string.Empty ? "style=\"--bs-aspect-ratio: " + ratio + "\"" : string.Empty;
164 string productGroupPromotionImage = string.Empty;
165 string productGroupPromotionImagePath = string.Empty;
166 string productGroupPromotionDescription = string.Empty;
167 string productGroupPromotionLinkLabel = string.Empty;
168 string productGroupPromotionLink = string.Empty;
169 string gridGap = !string.IsNullOrEmpty(productGroupPromotionImageTheme) ? "gap-0" : "gap-3";
170 string themePadding = !string.IsNullOrEmpty(productGroupPromotionImageTheme) ? "p-3" : "p-0";
171
172 foreach (FieldValueViewModel field in groupFields)
173 {
174 if (field.SystemName == "ProductGroupPromotionImage")
175 {
176 productGroupPromotionImage = field.Value != null ? field.Value.ToString() : string.Empty;
177 productGroupPromotionImagePath = "/Admin/Public/GetImage.ashx?Width=" + 480 + "&crop=0&image=" + "Files/Images/" + productGroupPromotionImage;
178 }
179 if (field.SystemName == "ProductGroupPromotionDescription")
180 {
181 productGroupPromotionDescription = field.Value != null ? field.Value.ToString() : string.Empty;
182 }
183 if (field.SystemName == "ProductGroupPromotionLinkLabel")
184 {
185 productGroupPromotionLinkLabel = field.Value != null ? field.Value.ToString() : string.Empty;
186 }
187 if (field.SystemName == "ProductGroupPromotionLink")
188 {
189 productGroupPromotionLink = field.Value != null ? field.Value.ToString() : string.Empty;
190 }
191 }
192 if (showProductGroupPromotionImage)
193 {
194 <div class="grid grid-1 mt-3 mx-3 @gridGap@(productGroupPromotionImageTheme)">
195 @if (productGroupPromotionImage != string.Empty)
196 {
197 productGroupPromotionLink = !string.IsNullOrEmpty(productGroupPromotionLink) ? productGroupPromotionLink : Model.Link;
198
199 <a href="@productGroupPromotionLink" title="@groupName">
200 <figure class="m-0@(ratioCssClass)" @ratioVariable>
201 <img class="img-fluid" src="@productGroupPromotionImagePath" alt="@groupName" style="object-fit:cover">
202 </figure>
203 </a>
204 }
205 @if (!string.IsNullOrEmpty(productGroupPromotionDescription) || !string.IsNullOrEmpty(productGroupPromotionLinkLabel))
206 {
207 <div class="grid grid-1 @themePadding ">
208
209 @if (!string.IsNullOrEmpty(productGroupPromotionDescription))
210 {
211 <h6 class="m-0">@productGroupPromotionDescription</h6>
212 }
213 @if (!string.IsNullOrEmpty(productGroupPromotionLinkLabel))
214 {
215 productGroupPromotionLink = !string.IsNullOrEmpty(productGroupPromotionLink) ? productGroupPromotionLink : Model.Link;
216
217 <a href="@productGroupPromotionLink" title="@productGroupPromotionLinkLabel" class="btn btn-link text-start border-0 p-0">@productGroupPromotionLinkLabel</a>
218 }
219 </div>
220 }
221 </div>
222 }
223 }
224 </div>
225 </div>
226 }
227 }
228 else
229 {
230 bool countrySelector = page.Item?["CountrySelector"] != null ? Convert.ToBoolean(page.Item["CountrySelector"].ToString()) : false;
231 bool languageSelector = page.Item?["LanguageSelector"] != null ? Convert.ToBoolean(page.Item["LanguageSelector"].ToString()) : false;
232 bool currencySelector = page.Item?["CurrencySelector"] != null ? Convert.ToBoolean(page.Item["CurrencySelector"].ToString()) : false;
233 string name = Translate("Preferences");
234 string icon = string.Empty;
235
236 if (languageSelector)
237 {
238 bool hideIcon = page.Item?["HideIcon"] != null ? Convert.ToBoolean(page.Item["HideIcon"].ToString()) : false;
239
240 if (!hideIcon)
241 {
242 icon = $"/Files/FlagIcons/{Pageview.Area.CultureInfo.Name.ToLower()}.svg";
243 }
244
245 name = reg.Replace(Pageview.Area.CultureInfo.DisplayName, string.Empty);
246 }
247
248 <form action="/Default.aspx?ID=@Model.PageId" data-response-target-element="PreferencesModalContent" data-layout-template="Swift_Preferences.cshtml" data-preloader="inline" class="w-100">
249 <input type="hidden" name="Layout" value="modal">
250 <input type="hidden" name="CurrentPageID" value="@Pageview.ID">
251 <input type="hidden" name="GroupID" value="@groupId">
252 <input type="hidden" name="ProductID" value="@productId">
253 <input type="hidden" name="VariantID" value="@variantId">
254 <a href="#" role="button" onclick="swift.PageUpdater.Update(event)" class="nav-link position-relative flex-fill swift_open-preferences-modal @activeClass @inPathClass" @(Model.IsActive ? "aria-current='page'" : "") data-bs-toggle="modal" data-bs-target="#PreferencesModal">
255 @if (icon != "")
256 {
257 if (Path.GetExtension(icon).ToLower() == ".svg" && !icon.ToLower().Contains("none"))
258 {
259 string iconPath = Dynamicweb.Context.Current.Server.MapPath(icon);
260
261 <span class="icon-2">@ReadFile(iconPath)</span>
262 }
263 }
264 <span>@name</span>
265 </a>
266 </form>
267 }
268 </div>
269