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
Solved! Go to Solution.
Views
Replies
Total Likes
Get the value of richtext in main.js , do the replace and continue with the same ${main.year}
Views
Replies
Total Likes
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).
Views
Replies
Total Likes
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
Views
Replies
Total Likes
Get the value of richtext in main.js , do the replace and continue with the same ${main.year}
Views
Replies
Total Likes
THank you for your community input!
Views
Replies
Total Likes
Thanks, Hemant.
I am doing the same right now. But I am wondering why the runtime variables are not working.
Views
Replies
Total Likes
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?
Views
Replies
Total Likes
Views
Likes
Replies