2016-11-23 105 views
1

我們對Sitecore的8.1更新3和玻璃映射器4.2.1.188GlassMapper渲染自定義鏈接字段

對於普通鏈路領域的經驗豐富的編輯和正常模式下其工作的罰款。

我們重複了核心數據庫中的General Link字段並刪除了「Javascript」菜單項。這是我們爲自定義鏈接字段進行的唯一更改。

這使得字段在體驗編輯器模式中消失。它在正常模式下很好。

@RenderLink(x => x.CallToActionButton, new { @class = "c-btn c-btn--strong c-btn--large" }, isEditable: true) 

編輯1:

當我使用Sitecore的現場呈示其所有的好。

@Html.Sitecore().Field(FieldIds.HomeCallToActionButton, new { @class = "c-btn c-btn--strong c-btn--large" }) 

任何建議,將不勝感激。

回答

2

您出現問題的原因是,Sitecore在生成經驗編輯器中顯示的代碼時檢查字段類型鍵。如果

Sitecore.Pipelines.RenderField.GetLinkFieldValue類檢查字段類型密鑰是linkgeneral link和你寫的,你抄襲了原General Link字段,以便您的字段的名稱是Custom Link或類似的東西。這意味着您的案例中字段類型密鑰是custom link(字段類型名稱小寫)。 SkipProcessor方法將custom link與字段類型鍵進行比較,並且由於它不同,處理器會忽略您的字段。

您不能簡單地將您的字段重命名爲General Link並將其放在Field Types/Custom文件夾中導致Sitecore不保留字段類型的ID(它存儲字段類型鍵)。

你可以做的是覆蓋Sitecore.Pipelines.RenderField.GetLinkFieldValue類和喜歡它的方法之一:

using Sitecore.Pipelines.RenderField; 

namespace My.Assembly.Namespace 
{ 
    public class GetLinkFieldValue : Sitecore.Pipelines.RenderField.GetLinkFieldValue 
    { 
     /// <summary> 
     /// Checks if the field should not be handled by the processor. 
     /// </summary> 
     /// <param name="args">The arguments.</param> 
     /// <returns>true if the field should not be handled by the processor; otherwise false</returns> 
     protected override bool SkipProcessor(RenderFieldArgs args) 
     { 
      if (args == null) 
       return true; 
      string fieldTypeKey = args.FieldTypeKey; 
      if (fieldTypeKey == "custom link") 
       return false; 
      return base.SkipProcessor(args); 
     } 
    } 
} 

,而是註冊它的原班:

<sitecore> 
    <pipelines> 
    <renderField> 
     <processor type="Sitecore.Pipelines.RenderField.GetLinkFieldValue, Sitecore.Kernel"> 
      <patch:attribute name="type">My.Assembly.Namespace.GetLinkFieldValue, My.Assembly</patch:attribute> 
     </processor> 
    </renderField> 
    </pipelines> 
</sitecore> 
+0

@馬雷克 - Musieklak Sitecore的被渲染字段權限。當我使用Sitecore Field helper時,它在Experience編輯器中都很好用。它僅在GlassMapper中發生? –

+0

什麼是FieldTypeKey? –

+0

字段類型鍵=字段類型名稱小寫。你有沒有嘗試過我上面寫的? –