Hi,
I am trying to author text in dialog, text contains dynamic values like name etc. I tried declaring sightly variable names in aem dialog to fetch the data dynamically but it didn't work.
I have authored a textarea widget (./desc) in aem dialog as "Hi ${model.name}, welcome to adobe forum." Where model is the sightly class object, and name is the variable declared in sightly wcmusepojo class.
In front I tried to get the text by adding ${properties.desc @context='html'}.
Can u help me how we can author the text dynamically.
Solved! Go to Solution.
Views
Replies
Total Likes
You cannot use variables in the dialog fields. Dialog fields have names (for example ./first) and you can fetch the names using code. If you are using WCMUsePojo - you can read the dialog fields and store them to a data member that belongs to a class. Then you can write out the value in the HTL front end. See:
Views
Replies
Total Likes
You cannot use variables in the dialog fields. Dialog fields have names (for example ./first) and you can fetch the names using code. If you are using WCMUsePojo - you can read the dialog fields and store them to a data member that belongs to a class. Then you can write out the value in the HTL front end. See:
Views
Replies
Total Likes
What you could do is something like this:
${ properties[model.varname]}
When model.varname gets a property-name, then that should work.
Views
Replies
Total Likes
Hi Feike,
I tried your suggestion it didn't work. I tried below approaches..
Approach 1:
/*
* Using String format
*/
String authoredText= "Hi %s, welcome to %s";
authoredText = authoredText.format(authoredText,"Kishore","AEM Quickstart");
log.info("---Using String format----\n"+authoredText);
Approach 2:
/*
* Using StrSubstitutor - org.apache.commons.lang.text.StrSubstitutor
*/
Map valuesMap = new HashMap();
valuesMap.put("name", "Kishore");
valuesMap.put("blog", "AEM Quickstart");
String templateString = "Hi ${name}, welcome to ${blog}.";
StrSubstitutor sub = new StrSubstitutor(valuesMap);
String resolvedString = sub.replace(templateString);
log.info("---Using StrSubstitutor----\n"+resolvedString);
Approach 3:
/**
* Using String replace
*/
String authoredText= "Hi ${name}, welcome to ${blog}";
authoredText = authoredText.replace("${name}","Kishore");
authoredText = authoredText.replace("${blog}","AEM Quickstart");
log.info("---Using String replace----\n"+authoredText);
From above approaches we can author the text in any of the format and parse it in java and we can get the text in HTL.
Views
Replies
Total Likes
No need for Java here, you can do this in HTL:
${'Page {0} of {1}' @ format=[current, total]} |
Views
Replies
Total Likes