Question

Photo of Andrew Metz

0

Lava list filter

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.

  • Photo of Jim Michael

    0

    Oh, sorry... I did misunderstand. I'm not sure if this is the most elegant way, but it's the best I can do:

    {% assign kids = Person | Children %}{{ kids | Map: 'NickName' | Join:', ' | ReplaceLast:',',' and' }}

    That's what you asked for, but as a fan of the Oxford Comma I think

    | ReplaceLast:',',', and' }}
    is more correct. :-)
    • Andrew Metz

      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

      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

      {% assign children = Person | Children %}{% for child in children %} {{ child.NickName }} - {{ child.BirthDate, }} {% endfor %}
      gives
      Johnny - 13/08/1993 12:00:00 AM Nadia - 27/06/2007 12:00:00 AM Nathanael - 28/09/1996 12:00:00 AM
      How to I get the date and not the time?

    • Ken Roach

      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

      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.

  • Photo of Jim Michael

    0

    There's a Lava filter for this: https://www.rockrms.com/lava/filters/person-filters#children

    Depending on where you're using it, you might have to replace CurrentPerson with Person.

    • Andrew Metz

      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

      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 %}