Homepage

Arrays

Last edit: Jul 14, 2023

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 app/views/pages/hobbies-test.liquid with the following content:

my hobbies: {{ context.params.hobbies }}

If you navigate to /hobbies-test?hobbies=music&hobbies=travelling you will learn that only the last element is displayed - 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..name

Questions?

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

contact us