Rendering files recursively

Hello,

given a collection “sections” residing in _sections and a page with multiple paragraphs, I’d like to create a section element for each paragraph. This I’d then include in my page but have the HTML for the section generated by some filter which abides by the layout specified in my section document, e.g instead of typing

{% for item in site.sections %}
  <h2>{{ item.title }}</h2>
  <p>{{ item.description }}</p>
  <p><a href="{{ item.url }}">{{ item.title }}</a></p>
{% endfor %}

I’d prefer to have the layout defined in the section’s front matter define how the section is rendered in the page

project/_layouts/page.html:

<html>
...

{% for item in site.sections %}
  {{ item | render }}
{% endfor %}

...
</html>

project/_layout/section.html

<h2>{{ item.title }}</h2>
<p>{{ item.description }}</p>
<p><a href="{{ item.url }}">{{ item.title }}</a></p>

project/_section/example.md:

---
title: Example section
description: An example
---

Hello World!

Does a filter like that exist? Is it possible to create this feature via plugins?

Kind regards and thanks in advance

I don’t think you can use liquid in the front matter like that - well, at all.

Also, if I am understanding you correcty the 2nd code block is where you are illustrating the front matter - front matter goes at the very top above anything else including the html tag.

You can use nested layouts. You can also pass parameters in to an include. I’m not sure if you can call a collection item from an include, maybe.

Data files are great in such a scenario. See tutorial