Glass.Mapper不适用于BeginRenderLink方法附加参数 [英] Glass.Mapper not applies additional parameters in BeginRenderLink method

查看:227
本文介绍了Glass.Mapper不适用于BeginRenderLink方法附加参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关Glass.Mapper BeginRenderLink 描述的方法来渲染应该包含多个HTML元素的链接: http://glass.lu/docs/tutorial/sitecore/tutorial22/tutorial22.html

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

我倒是想补充的是,自定义属性(类,样式),以该链接:

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.

下面是在Glass.Mapper来源发现BeginRenderLink:

Here is what was found in Glass.Mapper sources for BeginRenderLink:

    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 =真正的传递。

So if it is editing mode, no additional attributes are applied, only "haschildren=true" is passed.

我不知道是否有人在解决这个问题不知何故?

I wonder is anybody solve that issue somehow?

推荐答案

,因为它似乎这是用玻璃一个已知问题,已经有一个拉请求它挂起(的 https://github.com/mikeedwards83/Glass.Mapper/pull/73 )。

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).

我想,唯一的解决办法它是让从GitHub最新版本进行修正,并与修复重新编译玻璃。否则,你可以等待拉入请求得到批准和更新您的玻璃版本。正如你所看到的修复并不难(从这里):

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):

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);
 }

这篇关于Glass.Mapper不适用于BeginRenderLink方法附加参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆