Sitecore MVC and FieldRenderer.Render for Links

Gabbar picture Gabbar · Jul 25, 2014 · Viewed 9.8k times · Source

I'm trying to render a general link field like this - FieldRenderer.Render(item, "link").

This works as expected but how do I set custom text within the a tag that gets rendered. I want my output to look something like this

<a href="[link from sitecore]">[custom text from another field]</a>

Basically, the text for the link should come from another field on the item.

Thanks

Answer

Keith Murphy picture Keith Murphy · Sep 29, 2015

Jason has a great idea, but this functionality is out of the box.

@Html.Sitecore().BeginField("Link Field", new { haschildren= true })
@Html.Sitecore().Field("Text Field")
@Html.Sitecore().EndField()

No need to modify anything at all.