Skip to content

Instantly share code, notes, and snippets.

@rbaty-barr
Created February 21, 2017 15:30
Show Gist options
  • Save rbaty-barr/d0d8cd388d519f6d6d2f4234ae396f26 to your computer and use it in GitHub Desktop.
Save rbaty-barr/d0d8cd388d519f6d6d2f4234ae396f26 to your computer and use it in GitHub Desktop.
Render social sharing buttons on a page.
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
var pageID = ViewData["id"] != null ? ViewData["id"] : "1048";
var thePage = Umbraco.TypedContent(@pageID);
var theUrl = thePage.UrlAbsolute().ToString();
var theTitle = thePage.HasValue("socialShareTitle") ? thePage.GetPropertyValue("socialShareTitle") : "Important information from Segal Marco Advisors";
var theSummary = thePage.HasValue("socialShareDescription") ? thePage.GetPropertyValue("socialShareDescription") : "Need Default Summary";
var tweet = thePage.HasValue("twitterSocialShareDescription") ? thePage.GetPropertyValue("twitterSocialShareDescription") : theTitle;
var emailBody = theTitle + ": " + theSummary + " -- " + HttpUtility.UrlEncode(theUrl.ToString());
var emailSubject = "Information for you from Segal Marco Advisers";
}
@if(ViewData["id"] != null){
<ul class="share-buttons">
<li><a href="https://www.linkedin.com/shareArticle?mini=true&url=@HttpUtility.UrlEncode(@theUrl.ToString())&title=@HttpUtility.UrlEncode(@theTitle.ToString())&summary=@HttpUtility.UrlEncode(@theSummary.ToString())&source=@HttpUtility.UrlEncode(@theUrl.ToString())" target="_blank" title="Share on LinkedIn"><img alt="Share on LinkedIn" src="/media/1041/linkedin.png"></a></li>
<li><a href="https://twitter.com/intent/tweet?source=@HttpUtility.UrlEncode(@theUrl.ToString())&text=@HttpUtility.UrlEncode(@tweet.ToString())&via=segal_marco" target="_blank" title="Tweet"><img alt="Tweet" src="/media/1047/twitter.png"></a></li>
<li><a href="https://www.facebook.com/sharer/sharer.php?u=@HttpUtility.UrlEncode(@theUrl.ToString())&t=" title="Share on Facebook" target="_blank"><img alt="Share on Facebook" src="/media/1039/facebook.png"></a></li>
<li><a href="https://plus.google.com/share?url=@HttpUtility.UrlEncode(@theUrl.ToString())" target="_blank" title="Share on Google+"><img alt="Share on Google+" src="/media/1040/googleplus.png"></a></li>
<li><a href="mailto:?subject=@emailSubject&body=@HttpUtility.UrlPathEncode(@emailBody)" target="_blank" title="Send email"><img alt="Send email" src="/media/1038/email.png"></a></li>
</ul>
}
@rbaty-barr
Copy link
Author

call this like this... @Html.Partial("socialShareButtons", new ViewDataDictionary { { "id", @insight.Id }, {"title", @researchTitle} })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment