private List <Item> CreatePlaceholderItems(IEnumerable <Placeholder> placeholders) { var placeholdersFolderItem = _db.GetItem(_app.PlaceholdersPath); var placeholdersTemplate = _db.GetItem(Sitecore.JavaScriptServices.Core.TemplateIDs.PlaceholderSetting); // placeholdersInPlay is essentially a collection of all placeholders that are mentioned at least once // in any of the imported layouts, whether it's a preexisting placeholder item or a newly created one. var placeholdersInPlay = new List <Item>(); foreach (var placeholder in placeholders) { if (placeholdersFolderItem.Axes.GetDescendants().Any(x => x["Placeholder Key"] == placeholder.Key)) { placeholdersInPlay.Add(placeholdersFolderItem.Axes.GetDescendants().Where(x => x["Placeholder Key"] == placeholder.Key).First()); continue; } var calculatedId = _idManager.GetPredictableId(_app.Name, placeholder.Name, "layout-placeholders"); _idManager.AssertIdIsUnused(calculatedId, string.Format("placeholder setting {0}", placeholder.Name)); var newPlaceholderItem = placeholdersFolderItem.Add(placeholder.Name, placeholdersTemplate, calculatedId); newPlaceholderItem.Editing.BeginEdit(); newPlaceholderItem["Placeholder Key"] = placeholder.Key; newPlaceholderItem.Editing.EndEdit(); placeholdersInPlay.Add(newPlaceholderItem); } return(placeholdersInPlay); }