How to Subtract numbers in Slightly
Hi Team,
I would like to subtract two numbers in Slightly. I have used "-" symbol but its not working.
Example :
${itemList.Count-1}
Regards
MADHU
Hi Team,
I would like to subtract two numbers in Slightly. I have used "-" symbol but its not working.
Example :
${itemList.Count-1}
Regards
MADHU
Hi,
You cannot subtract using HTL (formerly known as Sightly). The purpose of Sightly is to be a template language, not a logical operator. For this type of scenario, the best approach is to use a Sling Model, where you can perform any custom operation and then expose it back to the HTML.
However, if you are trying to manipulate a list index, keep in mind you have these options available:
itemList: Object holding the following properties:
If you need to use the Sling model approach instead you could try something like this:
Sling Model:
@Model(adaptables = Resource.class)
public class MyModel {
@586265
private String propertyFromDialog;
@PostConstruct
protected void init() {
}
//Do your logic below. You can use the properties from the dialog once injected
public String getSubstraction() {
return 1;
}
}
Then in HTL
<sly data-sly-use.model="my.java.package.MyModel" />
<p>The result is: ${model.substraction}</p>
Please find more information here: https://redquark.org/aem/day-07-sling-models/#usage-in-htl
Hope this helps
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.