Back to Main Site

Contents

Filter Reference

Arrays

Within Fluid itself, the only way to create a simple array is to split a string.

{% assign children = "Alec,Gabrielle,Isabella" | split:"," %}

For simple arrays, you can access values by numeric index, as normal.

{{ children[0] }}
Alec

Note that an invalid index won’t throw an error, it just won’t return anything.

There are also several virtual members available.

{{ children.first }}
{{ children.last }}
{{ children.size }}
Alec
Isabella
3

There is no way to create a dictionary in Liquid, other than having it returned from a filter or virtual member.

For dictionary objects, you can access values with a bracket syntax (using double quotes or single quotes).

context.SetValue("children", new Dictionary<string,string>() {
  { "oldest", "Alec" },
  { "middle", "Gabrielle" },
  { "youngest", "Isabella" }
});
{{ children["oldest"] }}
Alec

The dictionary keys can also be used directly as members:

{{ children.oldest }}
Alec

The first and last filters and virtual members don’t return anything for dictionaries, though size works as you would expect.

An invalid key won’t throw an error, it just won’t return anything.

All arrays can be iterated using a for loop (see Looping).

Finally, there is an entire set of filters for working with arrays which provide additional features, including the wrapping of several of C#'s native array and LINQ functions