Expand my Community achievements bar.

SOLVED

Reading Dynamic Variables From RichText

Avatar

Level 2

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

1 Accepted Solution

Avatar

Correct answer by
Level 9

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

View solution in original post

6 Replies

Avatar

Level 10

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).

Avatar

Level 2

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

Avatar

Correct answer by
Level 9

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

Avatar

Level 10

THank you for your community input!

Avatar

Level 2

Thanks, Hemant.

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

Avatar

Level 10

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?