Reading time: 2 min read
Link Field Does Not Display If "Description" AKA Anchor Text Has No Value
But Sometimes You Want To Display a Link With No Visible Text
Start typing to search...
But Sometimes You Want To Display a Link With No Visible Text
// Constructor public ModelName() { TwitterLink = new HtmlString(FieldRenderer.Render(_item, "Twitter")); LinkField li = _item.Fields["Twitter"];
if (li != null) { TwitterLinkRaw = li.GetFriendlyUrl(); // Use authored anchortext value or pull the default anchortext value for this field from the dictionary to allow for support of multiple languages TwitterLinkDescRaw = !String.IsNullOrWhiteSpace(li.Text) ? li.Text : @Translate.Text("Twitter"); }}
@if (ViewHelper.IsEditMode())
{
@* Render the field directly in edit mode so that the user can visually modify the links *@
}
else
{
@* Preview or Normal modes *@
@* Ensure the link field has a URL which will be used to determine whether or not the link should be displayed *@
@* Use the authored link anchortext or a default value if it is not set *@
if (!String.IsNullOrWhiteSpace(Model.TwitterLinkRaw))
{
}
}
All the very best, Marcel