For Glass.Mapper BeginRenderLink described as method to render a link that should contain multiple HTML elements: http://glass.lu/docs/tutorial/sitecore/tutorial22/tutorial22.html
对于Glass.Mapper,BeginRenderLink描述为呈现应包含多个HTML元素的链接的方法:http://glass.lu/docs/tutorial/sitecore/tutorial22/tutorial22.html
What I'd like to add is custom attributes (class, style) to that link:
我要添加的是该链接的自定义属性(类,样式):
<% 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> <% } %>
This additional attributes works fine in normal mode but are not displayed in editing mode.
此附加属性在正常模式下工作正常,但在编辑模式下不显示。
Here is what was found in Glass.Mapper sources for BeginRenderLink:
以下是在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); }
So if it is editing mode, no additional attributes are applied, only "haschildren=true" is passed.
因此,如果它是编辑模式,则不应用其他属性,仅传递“haschildren = true”。
I wonder is anybody solve that issue somehow?
我想知道是否有人以某种方式解决了这个问题?
1 个解决方案
#1
0
As it seems this is a known issue with Glass and there is already a pull request pending for it (https://github.com/mikeedwards83/Glass.Mapper/pull/73).
因为看起来这是Glass的一个已知问题,并且已经有一个悬而未决的请求(https://github.com/mikeedwards83/Glass.Mapper/pull/73)。
I guess the only way to fix it is to get the latest version from GitHub make the fix and recompile the Glass with your fix. Otherwise you can wait for the pull request to get approved and update your Glass version. As you can see the fix is not that hard (taken from here):
我想解决它的唯一方法是从GitHub获取最新版本进行修复并使用您的修复程序重新编译Glass。否则,您可以等待拉取请求获得批准并更新您的Glass版本。正如你所看到的那样,修复并不那么难(从这里开始):
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); }
#1
0
As it seems this is a known issue with Glass and there is already a pull request pending for it (https://github.com/mikeedwards83/Glass.Mapper/pull/73).
因为看起来这是Glass的一个已知问题,并且已经有一个悬而未决的请求(https://github.com/mikeedwards83/Glass.Mapper/pull/73)。
I guess the only way to fix it is to get the latest version from GitHub make the fix and recompile the Glass with your fix. Otherwise you can wait for the pull request to get approved and update your Glass version. As you can see the fix is not that hard (taken from here):
我想解决它的唯一方法是从GitHub获取最新版本进行修复并使用您的修复程序重新编译Glass。否则,您可以等待拉取请求获得批准并更新您的Glass版本。正如你所看到的那样,修复并不那么难(从这里开始):
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); }