Figured it out.
In conf.py:
import os
GLOBAL_CONTEXT = {
...
'os': os,}
In .tmpl file:
{% set dir_path = 'path/to/directory' %}
{% set filenames = os.listdir(dir_path) %}
{% set file_list = [] %}
<ul>
{% for filename in filenames %}
{% set file_path = os.path.join(dir_path, filename) %}
{% if filename.endswith(".md") %}
{% set f = open(file_path, 'r') %}
{% set file_contents = f.read() %}
<li><a href="{{ filename }}">{{ filename }}</a></li>
{% endif %}
{% endfor %}
</ul>
On Tuesday, April 25, 2023 at 8:39:57 PM UTC-4 Mitch Berkson wrote:
> <https://stackoverflow.com/posts/76106352/timeline>
>
> I'm converting a web site from Hugo to Nikola. Hugo had some way of
> accessing all the files in a directory. Then I was able to read their
> metadata, etc. Is there a way to do this in a Nikola template file (using
> Jinja2 perhaps)?
>
--
You received this message because you are subscribed to the Google Groups
"nikola-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/nikola-discuss/263b05a5-af93-48e2-a617-83babc66ed5bn%40googlegroups.com.