You can add additional attributesBefore implementing this solution you will need to download the general link usinglatest nightly. I made a couple of changes to make it easier to solve this problem.
Ok, firstly create a sub-type to map the anonymous typeadditional link attributes onto, e.g.:
public @Html.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.RenderLinkData.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, xlinkField, =>config);
x link.LinkMyAttribute = 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)
new {@class
var myLink = classNamehtml.GetCompiled(field).Invoke(model) as MyLink;
return html.RenderLink(model,data_target= "#orderModal"field, new {data_type = myLink.MyAttribute}, falseisEditable, contents);
}
}
You could then create an extension methodAgain this only works with the latest nightly because I made some changes to IGlassHtml that acceptssupport this. If you don't want to use the correct parametersnightly you will need to copy and constructspaste some code from the anonymous type for other developersSitecoreFieldLinkMapper and the GlassHtml classes.