Thursday, October 30, 2014

Sitecore get URL for LinkField

A Sitecore template field of General Link type, can link to various items of various types (internal, external, media items and so on). Because each type would be rendered differently, when accessing these links in code, the different types need to be taken into account. The following method (found online) would take in a LinkField and output the URL as a string.

A LinkField comes from accesing a Sitecore item's template field liek follows: LinkField link = item.Fields["Field Name"]; This object can then be passed into the following method to get the correct URL:

No comments:

Post a Comment