多元文化中的 Sitecore 空场

Sitecore empty field in multi culture

这里简单介绍一下我的场景,

  1. 创建一个包含 2 个未版本化字段 SportAnimal
  2. 的模板
  3. 基于此模板以英语和阿拉伯语 2 种语言创建项目
  4. 对于英文版本,请在两个字段中填写 "I am English"
  5. 对于 Arabian,将 Animal 字段留空,并且 Sport -> 设置 Arabian value

结果:

当一个人请求带有 Context 的页面时,language = ArabianAnimal 字段将显示 I am English,而 Sport 将显示 Arabian value .

嗨,尼古拉·米蒂科夫, 我有两个未标记未版本化的字段,如上图所示。你们其他人的理解是 100% 正确的。我也没有实现任何自定义逻辑,也没有使用任何可能对此造成麻烦的扩展。 对于阿拉伯语和英语文化,我只是通过 sc_lang querystring 或 "ar" in url 使用不同的 url 来设置上下文语言,仅此而已。 下面是我的语言切换器简单代码:

public string ItemEnglishURL
{
    get
    {
        return string.Concat(Helper.GetItemUrlByCulture(Sitecore.Context.Item, "en"), CurrentQueryString);
    }
}

public string ItemArabicURL
{
    get
    {
        return string.Concat(Helper.GetItemUrlByCulture(Sitecore.Context.Item, "ar"), CurrentQueryString);
    }
}

public static string GetItemUrlByCulture(Item item, string culture)
{
    string itemUrl = string.Empty;
    if (item != null)
    {
        using (new Sitecore.Globalization.LanguageSwitcher(culture))
        {
            itemUrl = LinkManager.GetItemUrl(item, new UrlOptions() { LanguageEmbedding = LanguageEmbedding.Always });
        }
    }
    return itemUrl;
}

再多一个解释,基本上和我渲染时一样solution/scenario

           <li runat="server" id="navAncharLi"> 
              <a runat="server" id="navAnchar">
                 <sc:Text ID="TextTitle" Field="Title" runat="server" Item="<%# Item %>" DisableWebEditing="true" />
                 <strong runat="server" id="TagSubTitle">
                  <sc:Text ID="TextSubTitle" Field="SubTitle" runat="server" Item="<%# Item %>" DisableWebEditing="true" /> 
                  </strong> </a>
               <em runat="server" id="navAncharHead"></em>
            </li>


但是当我使用函数从后面的代码进行渲染时,它不会产生问题并且工作完美,如下面的代码所示:

                    <li runat="server" id="navAncharLi">
                        <a runat="server" id="navAnchar">
                          <%# GetFieldValue(Item,"Title") %>                                   
                            <strong runat="server" id="TagSubTitle">
                                 <%# GetFieldValue(Item,"SubTitle") %>                                        
                            </strong>                                    
                        </a>
                        <em runat="server" id="navAncharHead"></em>
                    </li>

public string GetFieldValue(Item itemObj, string fieldName)
    {
        return itemObj.Fields[fieldName].Value;
    }

但这似乎不是一个好的解决方案:)

赛义德

看起来您的情况正在发生语言回退,因为英语是 Sitecore 中设置的默认语言。我的回答是,每当您使用 getItem 函数传递当前上下文 lang 时,还要进行空点检查。

例如:

.GetItem(home.ID, language)

希望这能奏效!!

干杯!!

尼尚特

感谢大家, 最后在分析 Sitecore 支持后得出结论,这是因为 WFFM 错误已在新版本中解决。

Sitecore 支持的回复如下

I have investigated files and it seems the can be caused by the following bug in the WFFM module: https://sdn.sitecore.net/SDN5/Products/Web%20Forms%20for%20Marketers/Web%20Forms%20for%20Marketers%202,-d-,4/Release%20Notes/Release%20History.aspx An issue with incorrectly copied values in Title field while working with different content languages has been fixed (426013) The issue was fixed in the Web Forms for Marketers 2.4 rev. 150619 module version. Try to comment out the following processor in the Sitecore.Forms.Mvc.config:

     <renderField>
         <processor type="Sitecore.Forms.Mvc.Pipelines.Fields.AddFallbackValue,
 Sitecore.Forms.Mvc"
             patch:before="*[@type='Sitecore.Pipelines.RenderField.AddBeforeAndAfterValues,
 Sitecore.Kernel']" />
       </renderField>

Please let me know whether this helps

以上解决方案对我有效,sitecore 支持也证实了这一点。

You can comment this processor without any side effects for your solution. Alternatively, you can upgrade your WFFM module to the Web Forms for Marketers 2.4 rev. 150619 version: https://sdn.sitecore.net/Products/Web%20Forms%20for%20Marketers/Web%20Forms%20for%20Marketers%202,-d-,4/Module_Upgrades.aspx