Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Alexandre Locas 8 posts 88 karma points
    May 15, 2018 @ 19:23
    Alexandre Locas

    Let user insert variables in rich content editors

    Hi, we have some values that we don't want to be hard-coded in Umbraco. What would be the best approach to let user insert pre-definied "variables" in editor and then render those variables ?

    For exemple i would like to let my users create content such as : "You have until $$LIMIT_DATE$$ to send us bla bla bla..."

    And then have some code to replace variables ($$xyz$$) with values coming from a DB.

    Thank you

  • Frans de Jong 370 posts 1252 karma points c-trib
    May 16, 2018 @ 09:56
    Frans de Jong

    Interesting case.

    I think I would use a helper in the view. Something like:


    In that helper you can look for your special characters and replace it with a value. The only problem with this solution is that you need to access the database every pageload. To prevent that I would store the values in a settingsnode. Than it is cached and available as a Model so you can do something like:

    string.Replace("$$LIMIT_DATE$$", siteSettings.LimitDate);


  • Dan Diplo 1316 posts 4880 karma points MVP 2x c-trib
    May 16, 2018 @ 11:48
    Dan Diplo

    A very basic implementation would be something like:

    var richText = Model.Content.GetPropertyValue<IHtmlString>("content"); // or from model if you use model builder
    var replaced = new HtmlString(richText.ToString().Replace("$$LIMIT_DATE$$", replacementValue));
  • Alexandre Locas 8 posts 88 karma points
    May 17, 2018 @ 12:33
    Alexandre Locas

    Thanks Frans and Dan, two great ideas.

    I was looking for something more generic : a solution that would apply to all views maybe.

  • Frans de Jong 370 posts 1252 karma points c-trib
    May 17, 2018 @ 14:22
    Frans de Jong

    Can you elaborate more on what you are trying to do? The solutions above are usable in every view.

Please Sign in or register to post replies

Write your reply to: