The Sitecore Field Suite's General Links Field
I built the Sitecore Field Suite module a few months back to provide Sitecore users a more streamlined and informational approach to content authoring. The new Field Suite Module creates a new authoring experience with tooltips to view an item's path, in-line editing of referenced items, and visual indicators to let content authors know if their item and its referenced items are published. If you haven't read my previous blog post on the Field Suite module, I suggest you start there as this new field type builds on that post.
Why a new field type?
A project that I am currently working on called for a requirement outside of Sitecore's native functionality. The client needed to display widget on their page containing a list of internal and/or external links. At first I was thinking we could accomplish this by a rich text field, but as this would allow the client to enter any html the widget could easily break as it was not designed to handle images, tables and so on. Another approach would be to add multiple general link fields to the template. Although this would work, it would also be a maintenance and programming nightmare as each field needs to be wired and cannot be bound to a repeater. The more I thought about it, the more I realized that the best solution would be a new custom field.
General Link field vs. General Links field
The General Links field was created to solve a couple problems, so let's start by understanding Sitecore's General Link field. The General Link field is pretty verbose and allows the content author to make a single link to many different types of sources such as a content item or an external link. If you look at raw values you'll notice that Sitecore defines the link with an xml node with a variety of attributes such as LinkType, ID, and Anchor. The new General Links field wraps the same xml node in atag which allows us to hold many elements per field as shown in the xml code below. This code also makes it easier to read the value into xml and serialize each node into objects.
Sitecore's General Link field also does not give the capability to add Link Text to the link. Although we can counter this by having a single-line text field accompany a link field, the content author then has to set the link field and use the single-line text field to type in the text they would like that link to contain. With the General Links field we can easily click on one of the link items to put it in a selected state and simply click the "Set Link Text" button. Binding to a Repeater The new General Links field makes binding multiple links from Sitecore much easier than before. We are able to instantiate the field type and iterate over or bind the list of links to a repeater as shown in the example below.
Install the Package (You need to sign into Sitecore's Marketplace): Sitecore Marketplace
Download the Instructional Guide: Instructional Guide
Contribute to the Suite: GitHub