Skip to content

Instantly share code, notes, and snippets.

@kevsimpson
Created July 18, 2014 10:13
Show Gist options
  • Save kevsimpson/d30528b6e70e2138836e to your computer and use it in GitHub Desktop.
Save kevsimpson/d30528b6e70e2138836e to your computer and use it in GitHub Desktop.
Umbraco: social icon helpers
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
var homePage = CurrentPage.AncestorsOrSelf(1).First();
}
@RenderLinkIfNotEmpty(homePage.twitterUrl, "twitter", "Twitter")
@RenderLinkIfNotEmpty(homePage.facebookUrl, "facebook", "Facebook")
@RenderLinkIfNotEmpty(homePage.youtubeUrl, "youtube", "Youtube")
@RenderLinkIfNotEmpty(homePage.flickrUrl, "flickr", "Flickr")
@helper RenderLinkIfNotEmpty(dynamic link, string cssClass, string linkName) {
// A helper function is handy when you have to do the same thing over and over again
// So now we only have to write the "if" check and list item once, and we only need
// to put in the things that can vary
if (string.IsNullOrEmpty(link) == false) {
<a href="@link" class="@cssClass social__link" target="_blank"><i class="[email protected]()"></i></a>
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment