Before implementing this solution you will need to download the latest nightly. I made a couple of changes to make it easier to solve this problem.
Ok, firstly create a sub-type to map the additional link attributes onto, e.g.:
public class MyLink:Glass.Mapper.Sc.Fields.Link{
public string MyAttribute{get;set;}
}
Then create a new DataMapper:
public class SitecoreFieldMyLinkMapper : SitecoreFieldLinkMapper
{
public SitecoreFieldMyLinkMapper()
: base(new UrlOptionsResolver(), typeof(MyLink))
{
}
public override object GetField(Sitecore.Data.Fields.Field field, SitecoreFieldConfiguration config,
SitecoreDataMappingContext context)
{
if (field == null || field.Value.Trim().IsNullOrEmpty()) return null;
MyLink link = new MyLink();
LinkField linkField = new LinkField(field);
MapToLinkModel(link, linkField, config);
link.MyAttribute = linkField.GetAttribute("something");
return link;
}
}
Then create a HTML extension:
public static class HtmlExtensions
{
public static string RenderMyLink<T>(this IGlassHtml html, T model, Expression<Func<T, object>> field,
bool isEditable = false, string contents = null)
{
var myLink = html.GetCompiled(field).Invoke(model) as MyLink;
return html.RenderLink(model, field, new {data_type = myLink.MyAttribute}, isEditable, contents);
}
}
Again this only works with the latest nightly because I made some changes to support this. If you don't want to use the nightly you will need to copy and paste some code from the SitecoreFieldLinkMapper and the GlassHtml classes.