我試圖呈現這樣的一般鏈接字段 - FieldRenderer.Render(item, "link")
。Sitecore MVC和FieldRenderer.Render鏈接
這個按預期工作,但是如何在渲染的標籤中設置自定義文本。我想我的輸出看起來像這樣
<a href="[link from sitecore]">[custom text from another field]</a>
基本上,鏈接的文本應該來自該項目上的另一個字段。
感謝
我試圖呈現這樣的一般鏈接字段 - FieldRenderer.Render(item, "link")
。Sitecore MVC和FieldRenderer.Render鏈接
這個按預期工作,但是如何在渲染的標籤中設置自定義文本。我想我的輸出看起來像這樣
<a href="[link from sitecore]">[custom text from another field]</a>
基本上,鏈接的文本應該來自該項目上的另一個字段。
感謝
你可能想嘗試以下方法:
@Html.Sitecore().BeginField("Link Field")
//custom code
@Html.Sitecore().EndField()
Varun的的答案肯定是正確的,但是你會遇到一個問題,當內容編輯已經把一個值的的Description
場General Link
。鏈接渲染器將輸出描述以及BeginField
和EndField
方法之間的任何內容。
一個解決方案是允許一個額外的參數(HideDescription
),它可以隱藏描述。兩種可能的解決方案是;
Sitecore.Xml.Xsl.LinkRenderer
類自己會被放在停止其描述。Sitecore.Pipelines.RenderField.GetLinkFieldValue
將做一些後期渲染處理以去除說明之後,自定義管道的一步。選項2的侵襲性較小,但要確保結果是100%更難一點。一旦你有了這個,你可以渲染如下的字段;
@Html.Sitecore().BeginField("Link Field", new { HideDescription = true })
@Html.Sitecore().Field("Text Field")
@Html.Sitecore().EndField()
Jason有一個好主意,但這個功能是開箱即用的。
@Html.Sitecore().BeginField("Link Field", new { haschildren= true })
@Html.Sitecore().Field("Text Field")
@Html.Sitecore().EndField()
根本不需要修改任何東西。
是否有任何MVC API的參考? – Gabbar