I have a text element that shows names from a list of contacts dynamically.
Is it possible to take off the commas separating each name?
I have a text element that shows names from a list of contacts dynamically.
Is it possible to take off the commas separating each name?
The list operator that controls that is called â:join with
â. The default join is ", " as youâve discovered.
Whenever you render a list of texts, you can use :join with
to control the separator between the list items.
This isnât just a âcosmeticâ feature. You can also use it to do things like turn a list of texts into a proper JSON argument array to feed to an external API or whatnot. Itâs very handy! (Sort of a weird name, though, right?)
if i want it to be separated by an â&â, but only between the last 2 items, is it possible?
Sure. One way to do that (Iâm sure there are others) would be to get :count of the list first and subtract 1. Lets say your list has five names in it five-1 is 4. Youâll shove that into some custom state (or you might be able to do the math inline in your expression, hard to say) - letâs call it subcount. Display in your text element:
contacts:items until subcount:join with " " & contacts:last item
(Join the first 4 names with a space character. Then append an ampersand and display the last item.)
If you do this right, youâll get (Edit: my example was faulty â I said there were 5 names, not 4 as in my original output example):
Tom Dick Harry Julian & Jane
(Edit: there - fixed it. Five names. Four separated by space, the last preceded by an ampersand.)
but i never know a specific number of items that will be there, the amount always varies, so i cant hard code it
YOUâRE NOT HARD CODING IT. You get length from :count.
tnx, will try it
This topic was automatically closed after 70 days. New replies are no longer allowed.