split dynamic string value by space in Sightly | Community
Skip to main content
New Participant
March 31, 2022
Solved

split dynamic string value by space in Sightly

  • March 31, 2022
  • 3 replies
  • 2950 views

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

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by arunpatidar

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-p/179498/highlight/true

 

3 replies

Anmol_Bhardwaj
New Participant
March 31, 2022

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.

Ritesh_Mittal
New Participant
March 31, 2022

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 @arunpatidar .

arunpatidar
arunpatidarAccepted solution
New Participant
March 31, 2022
Arun Patidar