Combine posts from some but not all collections

I’m trying to create an array of pages from one or more (but not all) collections. Background, as you may guess from the code: I organize translations using collections and want to link to the translations that may or may not exist for each page. To do so, I want to create an array of all the pages that may be a translation, so that I can filter that array. This is what I came up with:

  {% assign page-translations = "" | split: "" %}
  {%- assign collections  = site.collections | where_exp: "item", "item.label != 'posts' and item.label != page.collection" -%}
  {%- for collection in collections -%}
    {% assign page-translations =  page-translations | concatenate collection %}
  {%- endfor -%}

This fails however, because Jekyll says “concat filter requires an array argument”. Apparently the collection isn’t an array. Of course I could create a template iterating through each collection, but by creating an array with the translations first, I can use that in several of my includes and avoid the need to do the filtering an additional two times.

I have a simple one liner solution already:

  {%- assign page-translations = site.documents | where: "translation-reference", page.translation-reference | where_exp: "item", "item.collection != page.collection" | sort: 'language' -%}

But I can imagine that becoming a performance issue, because it checks all documents instead of just the collections that may contain a translation.

Any ideas of how to combine pages from multiple collections?

1 Like

Hi @Koos, did you find a way to do it? I am trying to do the same thing, to loop through multiple collections, but facing the concatenation problem.

I didn’t find another solution, but realized the problem isn’t huge in my case, because I don’t expect the site to have many pages. If I understand it correctly, collections are for pages only, so I’d have to set up a similar lookup for posts, probably using categories.