0 Lava list filter 2 Andrew Metz posted 6 Years Ago I'm drawing a blank as to the best way to display a list of children in a family. I'd like it to display as a list the way you would write it in an email. i.e."Joe and Fred" or "Joe, Bob and Fred" or "Joe, Bob, Fred and Sara" It seems like there should be a lava filter for this. I stared writing my own conditional lava statement then got a headache. haha.Thanks.
Andrew Metz 6 years ago this works great and is actually way more elegant than the road I was going down. Oh and the oxford comma does have it's place. haha.
Ken Roach 6 years ago Flippin' AWESOME! Rock just keeps on getting better and better. Now... 1. Can your sort this list by age? 2. How can you list the birth dates? This would be ideal: Firstchild (1/3/1970), Secondchild (10/7/1973), and Thirdchild (15/11/1975). This would be helpful when sending a "thanks for your details" email to confirm we've entered the names and birth dates of the kids correctly.
Ken Roach 6 years ago {% assign children = Person | Children %}{% for child in children %} {{ child.NickName }} - {{ child.BirthDate, }} {% endfor %}givesJohnny - 13/08/1993 12:00:00 AM Nadia - 27/06/2007 12:00:00 AM Nathanael - 28/09/1996 12:00:00 AMHow to I get the date and not the time?
Ken Roach 6 years ago (edited 6 years ago) Thanks Jim. That worked!These all work:{% assign kids = Person | Children %} {{ kids | Map: 'NickName' | Join:', ' | ReplaceLast:',',', and' }}<br>{% assign bdays = Person | Children %} {{ bdays | Map: 'BirthDate' | Join:', ' | ReplaceLast:',',', and' }}<br>{% assign children = Person | Children %}{% for child in children %} {{ child.NickName }} - {{ child.BirthDate | Date: 'M/d/yy' }}, {% endfor %}I can't work out how to modify the output from the last line to read:Name1 - 08/13/98, Name2 - 06/27/07, and Name3 - 09/28/96 ?I can't see how to combine the two ideas
Jim Michael 6 years ago I'm not sure there's a way to do it... the map filter works on a single property at a time. If you're not hung up on the ", and" you could do {% capture kidslist %}{% assign children = Person | Children %}{% for child in children %} {{ child.NickName }} - {{ child.BirthDate | Date: 'M/d/yy' }}, {% endfor %}{% endcapture %}{{ kidslist | ReplaceLast: ',','' }}which will remove the last comma, but honestly, it seems like a very strange way to present information... a list of names makes sense as a sentence, but once you add another property (eg, "Billy - 1/1/2017, and Susie - "1/1/2018") it just reads really weird and you're better off just listing that info in a pseudo-table format.
Andrew Metz 6 years ago I guess I wasn't clear. I can get a list of children but I can't get them to format into a list.With commas and "and" before the last one. see examples above.Thanks
Andrew Metz 6 years ago If anyone else is looking for just how to get their names the lava is{% assign children = Person | Children %}{% for child in children %} {{ child.NickName }} {% endfor %}