Reading Dynamic Variables From RichText | Community
Skip to main content
amogh_d
New Participant
February 2, 2018
Solved

Reading Dynamic Variables From RichText

  • February 2, 2018
  • 6 replies
  • 3283 views

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 */

</div>

This is my richtext data:

Current year is ${main.year}

Thanks,
Amogh

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Hemant_arora

Get the value of richtext in main.js , do the replace and continue with the same ${main.year}

6 replies

smacdonald2008
New Participant
February 9, 2018

Are you simply trying to read the value of the RTE that a user entered into it and write the value out in a component?

amogh_d
amogh_dAuthor
New Participant
February 9, 2018

Thanks, Hemant.

I am doing the same right now. But I am wondering why the runtime variables are not working.

smacdonald2008
New Participant
February 7, 2018

THank you for your community input!

Hemant_arora
Hemant_aroraAccepted solution
New Participant
February 7, 2018

Get the value of richtext in main.js , do the replace and continue with the same ${main.year}

amogh_d
amogh_dAuthor
New Participant
February 7, 2018

Hi Scott,

Thanks for your reply.

I checked this component and this is not what I am looking for.  I specifically looking if we can replace dynamic variable of richtext property from sightly.

Thanks,
Amogh

smacdonald2008
New Participant
February 3, 2018

Looks like you want to use JS API with HTL. Using JaveScript with HTL is supported.

We have a HELPX Article that shows how to use JS API with HTL (and bootstrap)

Creating a Tab layout component for Adobe Experience Manager

(this is a tab layout for the component - not for a component dialog built with resource types).