Error executing template "Designs/Publications/Paragraph/Publication_ListComponentParagraph.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
at Dynamicweb.Content.Layouts.LayoutTemplateLocator.FindLayoutTemplateForPage(Page page)
at Dynamicweb.Frontend.Content.GetLayoutForDevice(Page page, DeviceType device)
at Dynamicweb.Frontend.Content.CreateGridContent(Int32 contentId, Boolean ignoreVisualEdit)
at Dynamicweb.Frontend.Content.RenderExternalGrid(Int32 pageId, String container)
at CompiledRazorTemplates.Dynamic.RazorEngine_9a39f2a918ba40f09c38505849add3a8.Execute() in D:\dynamicweb.net\Solutions\twodayco3\carbi.cloud.dynamicweb-cms.com\Files\Templates\Designs\Publications\Paragraph\Publication_ListComponentParagraph.cshtml:line 55
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 @{
5 List<ProductViewModel>? productList = null;
6 int productsOnEachPage = Convert.ToInt32(Model.Item.GetRawValueString("ProductsOnEachPage", "4"));
7 int listItemSourcePageId = Model.Item.GetInt32("ComponentSource");
8 string layout = Model.Item.GetRawValueString("Layout", "1");
9
10 if (Dynamicweb.Context.Current.Items.Contains("ProductListForPage"))
11 {
12 productList = (List<ProductViewModel>?)Dynamicweb.Context.Current.Items["ProductListForPage"];
13 }
14
15 //Fallback for Visual Editor
16 if (Pageview.IsVisualEditorMode || Pageview.Page.ItemType != "Publication_Catalog")
17 {
18 ProductViewModelSettings productSetting = new ProductViewModelSettings
19 {
20 LanguageId = Dynamicweb.Ecommerce.Common.Context.LanguageID,
21 CurrencyCode = Dynamicweb.Ecommerce.Common.Context.Currency.Code,
22 CountryCode = Dynamicweb.Ecommerce.Common.Context.Country.Code2,
23 ShopId = Pageview.Area.EcomShopId
24 };
25
26 productList = new List<ProductViewModel>();
27
28 for (int productCount = 0; productCount < 3; productCount++)
29 {
30 var productView = new ProductViewModel(){
31 Name = $"{Translate("Product")} {productCount}",
32 Id = productCount.ToString()
33 };
34 productList.Add(productView);
35 }
36 }
37 }
38
39 @if (productList?.Count > 0)
40 {
41 <div class="dwp-grid dwp-grid-cols-@(layout) dwp-grid-gap-2" data-item-type="@Model.Item.SystemName.ToLower()" data-id="@Model.ID">
42 @foreach (ProductViewModel listProduct in productList)
43 {
44 if (Dynamicweb.Context.Current.Items.Contains("ProductDetails"))
45 {
46 Dynamicweb.Context.Current.Items["ProductDetails"] = listProduct;
47 }
48 else
49 {
50 Dynamicweb.Context.Current.Items.Add("ProductDetails", listProduct);
51 }
52
53 if (listItemSourcePageId != 0) {
54 <div>
55 @RenderGrid(listItemSourcePageId)
56 </div>
57 }
58 }
59 </div>
60 }