Created
July 16, 2018 14:53
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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