Skip to content

Instantly share code, notes, and snippets.

@jonathanread
Created July 16, 2018 14:53
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 jonathanread/67f90bd39a9eea854e1de0febae165c8 to your computer and use it in GitHub Desktop.
Save jonathanread/67f90bd39a9eea854e1de0febae165c8 to your computer and use it in GitHub Desktop.
Replace a UserName key in a content block with the logged in users User Name
@model Telerik.Sitefinity.Frontend.ContentBlock.Mvc.Models.IContentBlockModel
@using Telerik.Sitefinity.Frontend.Mvc.Helpers
@using Telerik.Sitefinity.Security.Claims;
<div class="@Model.WrapperCssClass" @Html.InlineEditingAttributes(Model.ProviderName, Model.ContentType, Model.SharedContentID)>
<div @Html.InlineEditingFieldAttributes("Content", "LongText")>@ReplaceUserName(Model.Content)</div>
@{
if (Model.EnableSocialSharing)
{
@Html.SocialShareOptions(null);
}
}
</div>
@helper ReplaceUserName(string content)
{
string userName = "Not Logged In";
var identity = ClaimsManager.GetCurrentIdentity();
if (identity != null)
{
userName = identity.Name;
}
@Html.HtmlSanitize(content.Replace("{|UserName|}", userName))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment