# Merging sections into single loop

**URL:** <https://zola.discourse.group/t/merging-sections-into-single-loop/957>\
**Category:** Support\
**Created:** [June 24, 2021, 3:55pm UTC](https://zola.discourse.group/t/merging-sections-into-single-loop/957 "2021-06-24T15:55:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jamiedumont](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/jamiedumont/32/542_2.png) [@jamiedumont](https://zola.discourse.group/u/jamiedumont)\
**Post date:** [June 24, 2021, 3:55pm UTC](https://zola.discourse.group/t/merging-sections-into-single-loop/957/1 "2021-06-24T15:55:29Z")

</div>

Hey,

Just started playing with Zola and wondered if there was a way to group sections into a single collection that I could loop over?

The idea behind it is to have different sections like “article”, “photoset” or “bookmark” all with dates, but be able to view all of them in one feed reverse chronologically.

I’ve worked out how to get each using the `section.subsections` from the homepage and then `get_section()` with the results, but is there a way to merge and then sort these arrays?

Cheers, Jamie.

---

<div class="post-metadata">

**Author:** ![keats](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@keats](https://zola.discourse.group/u/keats)\
**Post date:** [June 24, 2021, 4:50pm UTC](https://zola.discourse.group/t/merging-sections-into-single-loop/957/2 "2021-06-24T16:50:18Z")

</div>

You have `transparent` for that, search for transparent in `https://www.getzola.org/documentation/content/section/`

---

<div class="post-metadata">

**Author:** ![jamiedumont](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/jamiedumont/32/542_2.png) [@jamiedumont](https://zola.discourse.group/u/jamiedumont)\
**Post date:** [June 24, 2021, 4:58pm UTC](https://zola.discourse.group/t/merging-sections-into-single-loop/957/3 "2021-06-24T16:58:38Z")

</div>

Thanks for the fast reply!

So in this case I’d wrap all my sections in a pseudo-section with all it’s children having `transparent: true`? That would let me iterate over them all at once.

Pushing my luck here, anyway to then also be able to view them individually? Would the `get_section()` approach work in this instance?

---

<div class="post-metadata">

**Author:** ![keats](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@keats](https://zola.discourse.group/u/keats)\
**Post date:** [June 24, 2021, 5:32pm UTC](https://zola.discourse.group/t/merging-sections-into-single-loop/957/4 "2021-06-24T17:32:55Z")

</div>

All `transparent` does is pass the pages to the parent sections, you can still view the transparent sections as usual.

---

<div class="post-metadata">

**Author:** ![jamiedumont](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/jamiedumont/32/542_2.png) [@jamiedumont](https://zola.discourse.group/u/jamiedumont)\
**Post date:** [June 24, 2021, 6:04pm UTC](https://zola.discourse.group/t/merging-sections-into-single-loop/957/5 "2021-06-24T18:04:32Z")

</div>

Brilliant! Thanks for the help!

* * *

**Edit with cut-down version of my final solution:**

I opted not to go with `transparent` only because it brings in other pages such as `/about` which don’t naturally have dates and then need filtering out of the loop.

Instead this a demonstrative example of what I did

```auto
  {% set blog = get_section(path="blog/_index.md") %}
  {% set photos = get_section(path="photos/_index.md") %}

  {% set feed = blog.pages | concat(with=photos.pages) %}

  {% for page in feed | sort(attribute="date") | reverse %}

    {% set section = page.components | first %}

    {% if section == "blog" %}
      <li><a href="{{ page.permalink | safe }}">{{ page.title }} - {{ page.date }}</a></li>
    {% endif %}

    {% if section == "photos" %}
      <img src="{{ page.extra.lead_image }}" />
      <li><a href="{{ page.permalink | safe }}">{{ page.title }} - {{ page.date }}</a></li>
    {% endif %}

  {% endfor %}

```

I preferred this solution as I’m likely to only ever have half a dozen sections I want to iterate over and it works better than `transparent` with other filters such as `slice`. An example was that I was fudging a date onto my other pages and simply not rendering them with my `section` check. However that threw off my `slice` filter if any of the dates happened to fall in the range I was after.

I have to tip my hat to the creators of Zola. It’s a very simple generator to understand (my other experiences are Hugo and Publish) but you can combine simple tools to order the data in quite complex ways. I also really appreciate the template language and explicit definition of template for each item of content (looking at you Hugo). Great work!
