I'm a beginner/learner to using Liquid templates and need some help with below query. I have a string with data coming in with three pipes ||| and this needs splitting based on "|||" as delimiter and send the data to multiple fields in the order as given below.
ex: Inputstring - Brilliant. Realistic. Constant suspense.|||Observer|||||||||||||||||||||Y
the above needs to be returned as : If the value is empty/null then those fields are not to be returned in output
The logic i have is :
{% assign SplitString = Inputstring | Split : "|||" %}
"Works" :{
"Work": {
"Text":"{{SplitString[0]}}",
"Filed2" :"{{SplitString[1]}}",
"Filed3" :"{{SplitString[2]}}",
"Filed4" :{{SplitString[3]}},
"Filed5" :{{SplitString[4]}},
"Filed6" :{{SplitString[5]}},
"Filed7" :{{SplitString[6]}},
"Filed8" :{{SplitString[7]}},
"Filed9" :{{SplitString[8]}},
"Filed10" :{{SplitString[9]}},
}
}
The above split logic is removing all of the empty pipe values and returning out put as
"Works" :{
"Work": {
"Text": "Brilliant. Realistic. Constant suspense.",
"Filed2" :"Observer",
"Filed3" :"Y"
}
}
Since fields 3-9 are all empty in input string they shouldn't be output however, the Filed10 value should be Y rather its been pulled in Filed3 which is not correct.
Can anyone please help and advise on what needs changing in my Logic? Thanks in advance.
Provided in the above section