Accessing files within a template

I’m working on a photography site and want to do page with just a bunch of photos, but right now the only solution I have is just to make a page, like gallery.html and then put a bunch of img tags

I looked at the get_image_metadata but that only works if I input the specific image file name.

I’d preferably like to get all filenames from a specific folder in the template and then be able to then use that to create my image tags so I don’t have to have to do this manually.

Something like this.

{% set filenames = get_path_filenames(path="static/images/photography/*.*", format=["jpg","png"]) %}

{%- for name in filenames -%}
    <img src="{{ name }}" class="gallery-image">
{%- endfor %}

This would also be a useful feature in combination with the load_data function because it would let you have a folder of json objects, iterate over all the json objects, and then load them with load_data something like this?

{% set filenames = get_path_filenames(path="static/data/*.*", format=["json"]) %}

{%- for name in filenames -%}
{% set data = load_data(name, format="json") %}
{%- endfor %}

Anyway thought it would be nice, and I didn’t see anything in the docs that let you access files like this without having a pre-compiled list of files in a text document or something.

1 Like

Hi,

Did you fix this?

Thanks.

I did not actually build this, it’s something I’d love to see able to be done in Zola which is why I posted it as a feature request.

I may consider looking into doing a PR for something like this at some point when I have time but for now this is just a feature request, and it seems that it’s something that’s been posted about before there’s some old posts from 2020/2021 that ask about this as well.

Most seem to take some approach with page.assets using asset colocation and the shortcode mentioned here but I have not been successful getting that to work, even though my images are in the same folder, the example in the documentation doesn’t work:

When printing page.assets I get an empty array, so unfortunately not sure what’s happening

1 Like

That does work, make sure you have a folder and an index.md page in there. See zola/docs/content/documentation/content/image-processing at master · getzola/zola · GitHub for how that page is setup in Zola