Arrays

Last edit: Nov 27, 2019
  • Contributors:
  • pavelloz
  • Slashek
  • diana-lakatos

Arrays are used to store multiple values for the same property.

Defining

You can use arrays by adding a property with type set to array, for example:

- name: hobbies
  type: array

Sending arrays to server

Consider a page views/pages/hobbies-test.liquid with the following content:

---
slug: hobbies-test
---
my hobbies: {{ context.params.hobbies }}

If you navigate to /hobbies-test?hobbies=music&hobbies=travelling you will see only the last element - travelling. To send an array of values, you need to add [] to the input name. Hence /hobbies-test?hobbies[]=music&hobbies[]=travelling displays the expected result: ["music","travelling"]

Tip

If you use Forms, you do not need to remember to add [] to the input name - we automatically detect if the property is defined as an array and it is already part of fields.properties.<property>.name

Questions?

We are always happy to help with any questions you may have.