Skip to main content
Level 4
Mar 4, 2016 10:49 AM UTC

String split in sightly

Hi All,

Is it possible to do string split in sightly. 

For example I have string x = "C-123-coursename"; I want to remove the course name and get C-123. How can i do this in sightly?

Thanks,

Shehjad

5 replies

edubey
Level 10
Mar 4, 2016 11:44 AM UTC

You can take help of javascript use api available in sightly

split using normal split() function and return value from file to sightly file

Here is one basic example available:[the link no longer available and removed by Mod]

Translate
Feb 5, 2025 9:19 AM UTC

Can you share the example link ?

Translate
narendiran_ravi
Level 6
Feb 7, 2025 4:01 PM UTC

You can achieve this using a Sling Model itself. Is there any specific reason you want to try this in Sightly?

Translate
Lokesh_Shivalingaiah
Level 10
Mar 4, 2016 2:34 PM UTC

Sightly templating script is designed not to have such logics other than just rendering piece of it. As @edubey mentioned, you can use JS Use API or do all that operations in your Sightly model or sling model class itself and send the actual value which needs to be displayed.

Translate
smacdonald2008
Level 10
Mar 4, 2016 3:06 PM UTC

If you want to know more about Sightly - watch out for this Months Ask the AEM COmmunity Experts. We will be doing a deep dive into Sightly. 

Translate