Hi there I’m was doing a static site by hand and I thought I would try zola instead.
The site is quite simple, it’s for displaying an image and have a button for previous and another for next. I wanted to display only the last post on the first page you see, so I edited index.html with
<div>
{% set page = get_page(path="tiras/second.md") %}
{{ page.content }}
</div>
but it’s showing the code instead of the page.
I also want to replace second.md by something that refers allways to the last post.
thanks in advance.
Oh I was not using “safe”… nevermind.
I still don’t get how do I get the last post.
Does zola has a section.pages.last ?
I was trying to do it like this, but it doesn’t work
<div>
{% set last_page = 0 %}
{% for page in section.pages %}
{% set last_page = loop.index %}
{% endfor %}
{{last_page}}
{% set page = get_page(path=f"tiras/tira{last_page}.md") %}
{{ page.content | safe }}
</div>
We actually just need:
{% set section = get_section(path="tiras/_index.md") %}
{% for page in section.pages %}
{% if loop.first %}
<h1>{{ page.title }}</h1>
{{ page.content | safe }}
welpo
October 28, 2024, 9:58am
6
If you’re just trying to get the last element (and don’t care about the other items), this should work:
{% section.pages | last %}
From the Tera docs .