Dynamic Variable Assignment
Hopefully you know that you can assign and use variables in liquid (if not, we need to talk..)
But what about situations where you need to dynamically create the variable name?
For example, what if you have five metafields to represent carousel slide data and want to loop through them?
It's possible - with the clever use of the append tag
﹛% for i in (1..5) %﹜
﹛% assign objectName = ‘image_carousel_slide_’ | append:i %﹜
﹛% if collection.metafields.my_fields[objectName] != blank %﹜
image carousel slide has content
﹛% endif %﹜
﹛% endfor %﹜
Thanks to Mathews Joseph for the excellent tip!