/// <summary> /// Renders the content. /// </summary> /// <param name="printContext">The print context.</param> /// <param name="output">The output.</param> protected override void RenderContent(Sitecore.PrintStudio.PublishingEngine.PrintContext printContext, System.Xml.Linq.XElement output) { if (!string.IsNullOrEmpty(this.ChildDataKeyName)) { printContext.Settings.Parameters[this.ChildDataKeyName] = this.DataSource; } if (!string.IsNullOrEmpty(this.DataSources)) { foreach (var dataSource in this.DataSources.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries)) { this.DataSource = dataSource; if (!string.IsNullOrEmpty(this.ChildDataKeyName)) { printContext.Settings.Parameters[this.ChildDataKeyName] = dataSource; } RenderChildren(printContext, output); } return; } this.RenderChildren(printContext, output); }
/// <summary> /// Preliminary render action invoked before RenderContent <see cref="RenderContent"/>. /// </summary> /// <param name="printContext">The print context.</param> protected override void BeginRender(Sitecore.PrintStudio.PublishingEngine.PrintContext printContext) { if (!string.IsNullOrEmpty(this.RenderingItem["Item Field"])) { var dataItem = this.GetDataItem(printContext); var data = dataItem[this.RenderingItem["Item Field"]]; if (!string.IsNullOrEmpty(this.RenderingItem["Item Selector"])) { var xpath = this.RenderingItem["Item Selector"]; if (!string.IsNullOrEmpty(xpath)) { var items = dataItem.Axes.SelectItems(xpath); if (items != null) { //this.DataSources = string.Join("|", items.Select(t => t.ID.ToString()).ToArray()); foreach (Item lookup in items) { this.DataSources = lookup[this.RenderingItem["Item Field"]]; } } } } Logger.Info("found DataSources: " + this.DataSources); Logger.Info("found DataSource: " + this.DataSource); } }
/// <summary> /// Preliminary render action invoked before RenderContent <see cref="RenderContent"/>. /// </summary> /// <summary> /// Renders the content. /// </summary> /// <param name="printContext">The print context.</param> /// <param name="output">The output.</param> protected override void RenderContent(Sitecore.PrintStudio.PublishingEngine.PrintContext printContext, System.Xml.Linq.XElement output) { if (!string.IsNullOrEmpty(this.ChildDataKeyName)) { printContext.Settings.Parameters[this.ChildDataKeyName] = this.DataSource; } if (!string.IsNullOrEmpty(this.RenderingItem["Search Query"])) { string searches = this.RenderingItem["Search Query"]; using (var context = ContentSearchManager.GetIndex("sitecore_master_index").CreateSearchContext()) { var items = LinqHelper.CreateQuery(context, SearchStringModel.ParseDatasourceString(searches)) .Select(toItem => toItem.GetItem()); //This gives us our IQueryable foreach (var item in items) { this.DataSource = item.ID.ToString(); if (!string.IsNullOrEmpty(this.ChildDataKeyName)) { printContext.Settings.Parameters[this.ChildDataKeyName] = item.ID.ToString(); } Logger.LogMessage("Found item: " + item.Name); RenderChildren(printContext, output); } } } }
/// <summary> /// Preliminary render action invoked before RenderContent <see cref="RenderContent"/>. /// </summary> /// <param name="printContext">The print context.</param> protected override void BeginRender(Sitecore.PrintStudio.PublishingEngine.PrintContext printContext) { if (!string.IsNullOrEmpty(this.RenderingItem["Item Reference"])) { this.DataSource = this.RenderingItem["Item Reference"]; } if (!string.IsNullOrEmpty(this.RenderingItem["Data Key"]) && printContext.Settings.Parameters.ContainsKey(this.RenderingItem["Data Key"])) { var data = printContext.Settings.Parameters[this.RenderingItem["Data Key"]].ToString(); if (!string.IsNullOrEmpty(data)) { var items = Sitecore.StringUtil.Split(data, '|', true); if (items.Count() > 1) { this.DataSources = data; return; } var contextItem = printContext.Database.GetItem(data); if (contextItem != null) { this.DataSource = contextItem.ID.ToString(); } } } // Get the data item assigned to the repeater var dataItem = this.GetDataItem(printContext); if (dataItem != null) { // apply the selector to the data item if (!string.IsNullOrEmpty(this.RenderingItem["Item Selector"])) { var xpath = this.RenderingItem["Item Selector"]; if (!string.IsNullOrEmpty(xpath)) { var items = dataItem.Axes.SelectItems(xpath); if (items != null) { this.DataSources = string.Join("|", items.Select(t => t.ID.ToString()).ToArray()); } } } else if (!string.IsNullOrEmpty(this.RenderingItem["Item Field"])) { // Get the number of times we need to repeat the child elements this.Count = dataItem[this.RenderingItem["Item Field"]]; } } }
/// <summary> /// Renders the content. /// </summary> /// <param name="printContext">The print context.</param> /// <param name="output">The output.</param> protected override void RenderContent(Sitecore.PrintStudio.PublishingEngine.PrintContext printContext, System.Xml.Linq.XElement output) { if (!string.IsNullOrEmpty(this.ChildDataKeyName)) { printContext.Settings.Parameters[this.ChildDataKeyName] = this.DataSource; } if (!string.IsNullOrEmpty(this.DataSources)) { foreach (var dataSource in this.DataSources.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries)) { this.DataSource = dataSource; if (!string.IsNullOrEmpty(this.ChildDataKeyName)) { printContext.Settings.Parameters[this.ChildDataKeyName] = dataSource; } RenderChildren(printContext, output); } return; } var dataItem = this.GetDataItem(printContext); if (dataItem == null && !printContext.Settings.IsClient) { return; } int count; if (!string.IsNullOrEmpty(this.Count) && int.TryParse(this.Count, out count) && count > 0) { for (int i = 0; i < count; i++) { // Render child elements this.RenderChildren(printContext, output); } return; } this.RenderChildren(printContext, output); }
/// <summary> /// Preliminary render action invoked before RenderContent <see cref="RenderContent"/>. /// </summary> /// <summary> /// Renders the content. /// </summary> /// <param name="printContext">The print context.</param> /// <param name="output">The output.</param> protected override void RenderContent(Sitecore.PrintStudio.PublishingEngine.PrintContext printContext, System.Xml.Linq.XElement output) { if (!string.IsNullOrEmpty(this.ChildDataKeyName)) { printContext.Settings.Parameters[this.ChildDataKeyName] = this.DataSource; } if (!string.IsNullOrEmpty(this.RenderingItem["Search Query"])) { Item Pages = this.RenderingItem.Parent; Item Cover = Pages.Children.First(); Item SearchCriteria = Cover.Axes.GetDescendant("Search Criteria"); // If the parameter for "parent item" is not null then use the above code. Logger.LogMessage("Found Search Criteria: " + SearchCriteria["Search Query"]); string searches = SearchCriteria["Search Query"]; using (var context = ContentSearchManager.GetIndex("sitecore_master_index").CreateSearchContext()) { var items = LinqHelper.CreateQuery(context, UIFilterHelpers.ParseDatasourceString(searches)) .Select(toItem => toItem.GetItem()); //This gives us our IQueryable foreach (var item in items) { this.DataSource = item.ID.ToString(); if (!string.IsNullOrEmpty(this.ChildDataKeyName)) { printContext.Settings.Parameters[this.ChildDataKeyName] = item.ID.ToString(); } Logger.LogMessage("Found item: " + item.Name); RenderChildren(printContext, output); } } } }