Index per Section

I feel like I’m missing something obvious here:

content
  - gear
      - index.md (or _index.md)
      - page.md
  index.md

I would like /content/gear/_index.md to render at /gear, and have /content/index.md render at / (the root). I’m unable to do this. It always renders content/gear/_index.md at /

So I found a way to get the result that I want, but I’m sure this is not ideal. I’m using this theme: GitHub - pawroman/zola-theme-terminimal: A simple, minimal retro theme for Zola

My goal is to have a static index page, content/_index.md rather than a listing of all pages, after a lot of wrangling with templates, I managed to do this by cloning the default index.html into a new template, and then adding a filter to it:

{%- for page in show_pages %}
                {%- if page.title == "Index" %}
                <div class="post on-list">
                    {{ post_macros::header(page=page) }}

                    {{ post_macros::content(page=page, summary=true, show_only_description=page.extra.show_only_description | default(value=false)) }}
                </div>
                {% endif -%}
            {% endfor -%}

and removing the paginator navigation links. Then I created a content/hello.md with title = "Index".

Is there a better way to do this?

You’re looping over all posts just to show a single one identified as “index”. There is indeed a simpler way.

In your _index.md, place any markdown you’d like to render. The index.html template doesn’t need to loop over the pages anymore. Try replacing that section with:

{{ section.content | safe }}

You might need to tinker with CSS / the templates a bit more, but this should be a good starting point.

1 Like