I'm trying to format a smart value list to stick it into a sentence for an email. I have an idea of what I will need to do with conditional logic (i.e. if there is one item, = do this, 2 = do this, 3 or more = do this) but where I'm stuck is formatting the "3 or more" section.
To be readable, I'd like to make it say "Service1, Service2, and Service3" with the "and" instead of another comma being where I'm struggling. I've been looking through documentation and I can't find anything, but it feels like something that might just be expected to know.
After digging around, what I've reached is:
{{#issue.affectedServices}} {{name}}{{^last}}, {{/}}{{/}}
Where I understand by putting "{{^last}}" it's saying do not put the comma after the last item in the list. What I don't understand is how to make it put an "and" in front of the last item of the list instead of a comma after the item.
Thank you!
Try this:
{{#issue.affectedServices}} {{#last}}and {{/}}{{name}}{{^last}}, {{/}}{{/}}
Omitting the final comma (before the 'and') is not easy, and arguably not desired (Oxford comma).
See the docs here for examples.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Victoria T
Yes, and...to what @Mykenna Cepek suggests...
You could also look at the conditional logic and/or new smart value list filtering for more complex formatting:
For example, you could use a test on {{issue.affectedServices.size}} to check the count for different layouts, concatenating them for 0 values, 1-2 values, or more than 2 values. Because only one would be non-empty you would get the expected result.
Kind regards,
Bill
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Mykenna Cepek Thank you! This is the exact sort of example I needed to understand what to do next. And you're right, I don't particularly care if the comma before "and" is committed or not. :)
@Bill Sheboy Oh yes, I'm having fun with the conditional logic for these rules. To anyone that might see this, .size is how I'm doing it and it's working.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
And if the Oxford Comma (or not) isn't pedantic enough for you, wait until you find yourself spending time adding a conditional to pluralize a word when the count is not equal to "1"!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.