concat

Concatenates (joins together) multiple arrays. The resulting array contains all the items from the input arrays.

Input

{% assign fruits = "apples, oranges, peaches" | split: ", " %}
{% assign vegetables = "carrots, turnips, potatoes" | split: ", " %}

{% assign everything = fruits | concat: vegetables %}

{% for item in everything %}
- {{ item }}
{% endfor %}

Output

- apples
- oranges
- peaches
- carrots
- turnips
- potatoes

You can string together concat filters to join more than two arrays:

Input

{% assign furniture = "chairs, tables, shelves" | split: ", " %}

{% assign everything = fruits | concat: vegetables | concat: furniture %}

{% for item in everything %}
- {{ item }}
{% endfor %}

Output

- apples
- oranges
- peaches
- carrots
- turnips
- potatoes
- chairs
- tables
- shelves

Output

- business
- celebrities
-
- lifestyle
- sports
-
- technology

By using compact when we create our site_categories array, we can remove all the nil values in the array.

Input

{% assign site_categories = site.pages | map: "category" | compact %}

{% for category in site_categories %}
- {{ category }}
{% endfor %}

Output

- business
- celebrities
- lifestyle
- sports
- technology
PDF HTML Epub Powered by Read The Docs