SitecoreLinked: Undocumented but useful!

Glass.Mapper is a very type-safe way of programming in Sitecore using templates. Among other things, it allows you to map the fields of an item to the properties of an object.

One of the undocumented features is the SitecoreLinked attribute. It is only given stage time at one of the Glass tutorials, without further explanation. It allows you to map a list of linked items to an IEnumerable, like the Navigate > Links Sitecore Ribbon button does.

Sometimes, you don’t want all linked items, but only incoming or outgoing links. For this, add Option = SitecoreLinkedOptions.References or Option = SitecoreLinkedOptions.Referrers to the SitecoreLinked attribute.


[SitecoreType(TemplateId = "D3F78276-354C-4265-AE29-BBEC0EFEF04F")]
public class MainItem
{
[SitecoreLinked(InferType=true)]
public virtual IEnumerable AllLinkedItemsAsList { get; set; }

[SitecoreLinked(InferType=true, Option = SitecoreLinkedOptions.Referrers)]
public virtual IEnumerable IncomingLinkedItemsAsList { get; set; }

}

To just get a list of all items linked in a particular field, you don’t need the SitecoreLinked attribute, only a SitecoreField attribute:


[SitecoreType(TemplateId = "D3F78276-354C-4265-AE29-BBEC0EFEF04F")]
public class MainItem
{
[SitecoreField(FieldId = "168CBC07-46F8-4EA2-9E35-855493720DEA")]
public virtual IEnumerable RelatedItemsAsList { get; set; }
}

[SitecoreType(TemplateId = "AE63A28F-9D86-4752-9F09-6B094062EB6B")]
public class Related
{
}

(Slightly) more info to be found at:

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.