Dynamic text strings in TinyMCE

Vote:
 

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?

#331967
Oct 25, 2024 19:51
Vote:
 

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);
    }
}



#331969
Edited, Oct 25, 2024 20:39
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.