Knowledge Drop

Using liquid 'split' to iterate (loop) over a string

  • 5 April 2021
  • 0 replies
  • 1255 views

Userlevel 5
Badge
  • Looker Staff
  • 172 replies

Last tested: May 2020

 

This comes in handy when you has a comma-separated list and you want to format it or apply links to each comma-separated value.

For example:

List
apple, banana
orange, apple, banana

Since the "list" fields can have either 2 values or 3, we can easily use the split function to format the list with bullet points regardless of how many values there are.

dimension: list {    type: string    sql: ${TABLE}.list ;;    html:      {% assign words = {{value}} | split: ',' %}    <ul>    {% for word in words %}    <li> {{ word }} </li>    {% endfor %} ;;  }

This generates a bullet list on our original comma-separated list.

Link to Shopify Documentation on split

 

This content is subject to limited support.                


0 replies

Be the first to reply!

Reply