6 Replies Latest reply on Feb 9, 2018 10:49 AM by smacdonald2008

    Reading Dynamic Variables From RichText

    amogh_d Level 1

      Is there any way to replace the ${varableTest} variables in sightly, variables which are set in the RichText while authoring? I know there is an insertVariable plugin available which can be used to insert those variables in RTE, but how to replace them while rendering text on the page.


      I am not looking for the replacing them by reading the ${} first and replacing them after that. I just want to replace them with some existing available variables on the page. Below is the sample snippet:


      This is my use function:

      use(function () {

          var Calendar = Packages.java.util.Calendar;

          var currentYear = Calendar.getInstance().get(Calendar.YEAR);

            return {

              year: currentYear




      This is my HTML file with sightly:


      <div class="page__main" data-sly-use.main="main.js">

                     ${properties.richText@ context="html"}  /* I want to replace inserted vaiable with js (year) variable value */



      This is my richtext data:


      Current year is ${main.year}