Section.pages to search recursively for all sub-folders/directories

Is it possible that the “section.pages” as in Sections and Pages search all sub-folders/directories recursively? Is there a setting or way to do this?

(It seems that mine only return the pages in the directory.)

Thanks!

1 Like

maybe I misunderstood you, but try to use the macro like :

{% macro tree() %}
        {% for subsection in section.subsections | sort %}
            {% set subsection_item = get_section(path=subsection) %}  
               {{ subsection_item.title  }}
            {% endfor %}
{% endmacro tree %}

I think your code is right (using the “subsections”), but I’m not sure how to use “macro tree()”. I’m getting this error:

Failed to build the site
Error: Error parsing templates
Reason:

  • Failed to parse “/path/zola/templates/articles/index.html”
    –> 65:17
    |
    65 | {% macro tree() %}␊
    | ^—
    |
    = unexpected tag; expected an else tag, an endfor tag ({% endfor %}), or some content

Can you provide some help how to use macro tree()?

Thanks!

That depends on your usecase. You can make all subdirectories transparent if that’s what your site wants to do.

Macros have to be defined in another file and imported: https://tera.netlify.com/docs/#macros

1 Like

What are the conditions for the the subsection field to be included in the context?

The Sections and Pages docs say:

Whichever template you decide to render, you will get a section variable in your template with the following fields:

// Direct subsections to this section, sorted by subsections weight
// This only contains the path to use in the `get_section` Tera function to get
// the actual section object if you need it
subsections: Array<String>;

But I’m not getting a subsections or pages variable for nexted index.md files (i.e., one directory below content). And for _index.md files, they redirect to root* instead of making a page, so I can’t check the output of {{ __tera_context }}.

*when redirect_to="" is set in the front matter

It’s only the direct subsections. Subsections of subsections are not going to be included.