If your editors accept writing actual things like: "You have donated ${DonatedAmt} this year", you could let them do that.
Add a display template like this, filename: XhtmlString.cshtml:
@using EPiServer.Core
@model XhtmlString
@{
if (Model == null) { return; };
}
@{Html.RenderXhtmlString(Model.ReplacePlaceholders());}
Then, something like this:
public static class XhtmlStringExtensions
{
public static XhtmlString ReplacePlaceholders(this XhtmlString xhtmlString)
{
var contextModeResolver = ServiceLocator.Current.GetInstance<IContextModeResolver>();
if (contextModeResolver.CurrentMode == ContextMode.Edit)
{
return xhtmlString;
}
var processedText = xhtmlString.ToInternalString().Replace("${DonatedAmt}", "1234");
return new XhtmlString(processedText);
}
}
Hi,
If you're just interested in replacing placeholder tokens in XhtmlString properties then what Tomas suggested is a great way to do it without too much worry about unintended consequences. You can even use a UIHint and display template to apply that same approach to just specific properties.
If you're looking for something more far-reaching which would allow you to use the token in any property (or even in the markup in your views) then it would be worth taking a look at this article from David Knipe:
https://www.david-tec.com/2017/11/tokenised-content-in-episerver/
The approach in that article involves creating a filter which will replace the token in the generated HTML before it's returned in the HTTP response to the client. You can apply it globally or to individual controllers but it will replace any instance of the token regardless of where it is within the response.
Hi there,
I am wondering if there is a way to pass a calculated value into the TinyMCE editor. For example, when a user logs in, a message can be displayed "You have donated ${DonatedAmt} this year".
Still using CMS 11 and have read posts about dynamic content being deprecated with the recommendation to use a blocks. However, seems like there are issues with nested blocks and rendering inline so was curious if there had been any more recent solutions proposed for something like this?