Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

split dynamic string value by space in Sightly

Avatar

Level 3

How to split dynamic string value by space in Sightly.

Ex: ${item.fullName} gives 'firstname secondname'. I want to split this by space to get 'firstname' and 'secondname'.

Please help.

Thanks in advance

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor
3 Replies

Avatar

Correct answer by
Community Advisor

Hi @Dolly 
You can't do this directly in HTL.

you have to Use Java or JS Use API.

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/string-split-in-sightly/m-...

 

Avatar

Community Advisor

Hi @Dolly ,

 

HTL/Sightly is for view/presentation. Let's go one step back, how will you make sure the full name will have only one space in between. Full name can have multiple words (middle name, or sometime more than three). Better you have separate fields in the Sling Model for firstName and lastName (or more) and then use them in HTL. 

 

Though your original question has been answered by @Arun_Patidar .

Avatar

Community Advisor

This is not possible with Sightly.

This is from official documentation:

Separation of Concerns: The expressiveness of the Sightly template language is purposely limited, in order to make sure that a real programming language is used to express the corresponding presentation logic. This optional logic is invoked from Sightly expressions with the Use-API pattern, making it easy to understand what is called for a given view, and to potentially have different logic for different views of the same resource.