对于Glass.Mapper BeginRenderLink ,描述为呈现应包含多个HTML元素的链接的方法:http://glass.lu/docs/tutorial/sitecore/tutorial22/tutorial22.html
我想要添加的是该链接的自定义属性(类,样式):
<% using (BeginRenderLink(x => x.Image1Link,
new NameValueCollection
{ { "class", "image-banner" }, { "style", string.Format("background-image: url({0})", Model.Image1.Src) } }, true))
{ %>
<span class="image-banner-wrapper">
<span class="image-banner-content"><%= Editable(x => x.Image1Text) %></span>
</span>
<% } %>
此附加属性在正常模式下正常工作,但在编辑模式下不显示。
以下是在BeginRenderLink的Glass.Mapper源代码中找到的内容:
if (IsInEditingMode && isEditable)
{
return MakeEditable(field, null, model, "haschildren=true", _context, SitecoreContext.Database, writer);
}
else
{
return BeginRenderLink(field.Compile().Invoke(model) as Fields.Link, attrs, string.Empty, writer);
}
因此,如果它是编辑模式,则不会应用其他属性,只会传递“haschildren = true”。
我想知道是否有人以某种方式解决了这个问题?
答案 0 :(得分:0)
因为看起来这是Glass的一个已知问题,并且已经有一个待处理的拉取请求(https://github.com/mikeedwards83/Glass.Mapper/pull/73)。
我想解决这个问题的唯一方法是从GitHub获取最新版本进行修复并使用您的修复程序重新编译Glass。否则,您可以等待拉取请求获得批准并更新您的Glass版本。正如您所看到的那样,修复并不那么困难(取自here):
if (IsInEditingMode && isEditable)
{
if (attrs != null)
{
attrs.Add("haschildren", "true");
return MakeEditable(field, null, model, attrs, _context, SitecoreContext.Database, writer);
}
return MakeEditable(field, null, model, "haschildren=true", _context, SitecoreContext.Database, writer);
}