Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parkersweb/bde18f6b7c507e99ab5f to your computer and use it in GitHub Desktop.
Save parkersweb/bde18f6b7c507e99ab5f to your computer and use it in GitHub Desktop.
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@using PG.UmbracoExtensions.Helpers
@*
OPEN GRAPH METATAGS widget
Used by social networks to fetch right data about page (shared).
Must be inserted in head element with prefix="og: http://ogp.me/ns#" attribute.
Required content node properties: metaDescription
NOTE: set "sharingImageUrl" to default sharing image url
*@
@{
var sharingImageUrl = ""; //doesn't work with //
String sharingDescription = Model.Content.GetPropertyValue<String>("metaDescription");
if (String.IsNullOrEmpty(sharingDescription))
{
if (Model.Content.HasProperty("shortText") && Model.Content.HasValue("shortText"))
{
sharingDescription = Umbraco.StripHtml(Umbraco.Truncate(Model.Content.GetPropertyValue<String>("shortText"), 200, true).ToString()).ToString();
}
else
{
sharingDescription = Umbraco.Field("metaDescription", recursive: true).ToString();
}
}
if (Model.Content.HasProperty("thumbnail") && Model.Content.HasValue("thumbnail"))
{
sharingImageUrl = Umbraco.GetFullUrl(Model.Content.GetThumbnailUrl());
}
}
<meta property="og:title" content="@Umbraco.Field("pageName")" />
<meta property="og:description" content="@sharingDescription" />
<meta property="og:url" content="@library.NiceUrlWithDomain(Model.Content.Id);" />
<meta property="og:image" content="@sharingImageUrl" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment