private void LoadFeaturedProducts() { var sortField = ProductSortByField.FromString(Convert.ToString(Settings[FeaturedSettings.SortBy])) ?? new ProductSortByField() { Field = "Name", SortDirection = SortDirection.ASC }; var categoryIds = Convert.ToString(Settings[FeaturedSettings.CategoryFilterCategoryIds]).Split(',').Select(x => WA.Parser.ToInt(x).GetValueOrDefault(-1)).ToList(); bool matchAll = Convert.ToString(Settings[FeaturedSettings.CategoryFilterMethod]).ToLower() == "all"; var products = ProductCollection.FindProductsByCategories(categoryIds, sortField, matchAll); int maxProducts = WA.Parser.ToInt(Settings[FeaturedSettings.MaxNumProducts]).GetValueOrDefault(25); if (products.Count > maxProducts) { products = products.Take(maxProducts).ToList(); } string tplHeader = Settings[FeaturedSettings.TemplateHeader].ToString(); string tplProduct = Settings[FeaturedSettings.TemplateProduct].ToString(); string tplFooter = Settings[FeaturedSettings.TemplateFooter].ToString(); string tplNoResults = Settings[FeaturedSettings.TemplateNoResults].ToString(); if (products.Count == 0) { litTemplateOutput.Text = tplHeader + tplNoResults + tplFooter; } else { var productTokenizer = new ProductTokenValueProvider(StoreContext); var templateProcessor = new TemplateProcessor(productTokenizer); StringBuilder productsHtml = new StringBuilder(products.Count); foreach (var p in products) { productTokenizer.Product = p; productsHtml.Append(templateProcessor.ProcessTemplate(tplProduct)); } litTemplateOutput.Text = tplHeader + productsHtml.ToString() + tplFooter; } }