In the early days of umbraco, it could be said that to create complex sites you would end up needing to have many many nodes. A common thing you encounter on a website is a list and being that we are developing in Umbraco we want to make that list CMS’able. Your options were to create individual nodes or to give the user free reign and use a rich text editor. Teh rich text editor is just a bad idea because I have found that if you do give the power to the user, then they will find a way to mess it up. If each item in the list is only a line of text, then you end up creating a node for each line of text which just becomes messy and overkill. There is a package out there for this problem. It is the repeatable custom content package. http://our.umbraco.org/projects/backoffice-extensions/repeatable-custom-content
This package is quite excellent in being able to repeat pieces of information from as simple as a single line of text in the example above or as complex as a table with multiple text inputs and booleans. What I have found to be the most helpful with these repeatable custom content elements that I have created is to put them into an object (or a predefined object, if avaible) and then attach them to a repeater on a usercontrol to display them.
In the single line of text example, I am just using a string as my object and then I create a List of strings which I load with the content from my umbraco node:
public static List<string> GetValuesFromListing(int nodeId, string propertyAlias)
{
List<string> values = new List<string>();
// Get the XML for the umbraco node
XPathNodeIterator xpathIterator = umbraco.library.GetXmlNodeById(nodeId.ToString());
XElement node = XElement.Parse(xpathIterator.Current.OuterXml);
// Get the linked list node
var list = node.Descendants(propertyAlias).FirstOrDefault();
if (list != null)
{
// Loop over all the nodes in the linked list
foreach (var value in list.Descendants(“data”))
{
if (!string.IsNullOrEmpty(value.Value))
{
values.Add(value.Value.ToString());
}
}
}
return values;
}
Then, on my user control, I create a Repeater control and use my List<string> of items from my repeatable custom content as my datasource in order to have my HTML separated from logic.
One area where I have found repeatable custom content lacking is in the media picker as once the piece of media is selected, the preview of the image is not shown which makes it a bit difficult for the user to know what has been previously selected. Fortunately, there is another great package out there for this purpose. The Digibiz Advanced Media Picker: http://our.umbraco.org/projects/backoffice-extensions/digibiz-advanced-media-picker
This works on the same idea but just with media items. They have just released a new version and it is full of great features such as restricting which types of media can be uploaded in addition to their other features of restricting how many pieces of media you want to use and getting to choose how to export the data. You would get the data out in the same was as above in traversing the XML (obviously the code will be a bit different from above because the XML will be laid out differently) and parsing it into an object which can then be used in a repeater.
So, there are a couple of options in repeating content in Umbraco which is a real boost to keeping things clean in your back end in addition to proper restrictions on the CMS editor.