# New global functions \`get\_files\` or similar

**URL:** <https://zola.discourse.group/t/new-global-functions-get-files-or-similar/307>\
**Category:** Feature requests\
**Created:** [January 22, 2020, 9:07am UTC](https://zola.discourse.group/t/new-global-functions-get-files-or-similar/307 "2020-01-22T09:07:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![simao](https://avatars.discourse-cdn.com/v4/letter/s/e56c9b/32.png) [@simao](https://zola.discourse.group/u/simao)\
**Post date:** [January 22, 2020, 9:07am UTC](https://zola.discourse.group/t/new-global-functions-get-files-or-similar/307/1 "2020-01-22T09:07:45Z")

</div>

Sometimes it’s useful to iterate over files to use them in templates. You can do this using `page.assets`, but this does not include files that are not colocated with that page.

We could have a `get_files(path=<some path>)` that returns a list of files in `path`. Optionally we could make that recursive.

Additionally, it would be useful for `get_files` to accept some glob, for example `get_files(path=<some_path>, glob="*.jpg")`, because otherwise looping over the returned vector might be a big cumbersome.

With the `glob`, if you want to iterate over images in `static/mypost` you could just do:

```auto
{% for asset in get_files(path=static/page.slug, glob="*.jpg") %}
{% if loop.index is odd %}<div class="row">{% endif %}
  <div class="column">
    <a class="gallery-item" href="{{ get_url(path=asset) }}" >
      <img src="{{ get_url(path=asset) }}">
    </a>
  </div>
{% if loop.index is even or loop.last %}</div>{% endif %}  
{% endfor %}

```

Otherwise you would need to filter the elements inside a loop, which messes with the `loop.*` variables, which are sometimes useful for templating, you would have to write something like:

```auto
{% set_global idx = 0 %}
{% for asset in page.assets %}
{% if asset is matching("[.](jpg)$") %}
{% set_global idx = idx + 1 %}
{% if idx is odd %}<div class="row">{% endif %}
  <div class="column">
    <a class="gallery-item" href="{{ get_url(path=asset) }}" >
      <img src="{{ get_url(path=asset) }}">
    </a>
  </div>
{% if idx is even or loop.last %}</div>{% endif %}
{% endif %}
{% endfor %}

```

What do you think?

---

<div class="post-metadata">

**Author:** ![keats](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@keats](https://zola.discourse.group/u/keats)\
**Post date:** [January 22, 2020, 4:49pm UTC](https://zola.discourse.group/t/new-global-functions-get-files-or-similar/307/2 "2020-01-22T16:49:04Z")

</div>

I think this is a better idea than [https://github.com/getzola/zola/pull/931](https://github.com/getzola/zola/pull/931) but at the same time the workaround is not that bad so I don’t know if it’s useful enough to warrant being added.

---

<div class="post-metadata">

**Author:** ![simao](https://avatars.discourse-cdn.com/v4/letter/s/e56c9b/32.png) [@simao](https://zola.discourse.group/u/simao)\
**Post date:** [January 22, 2020, 5:16pm UTC](https://zola.discourse.group/t/new-global-functions-get-files-or-similar/307/3 "2020-01-22T17:16:23Z")

</div>

You mean the second code sample above? That would only work with [https://github.com/getzola/zola/pull/931](https://github.com/getzola/zola/pull/931) though.

---

<div class="post-metadata">

**Author:** ![keats](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@keats](https://zola.discourse.group/u/keats)\
**Post date:** [January 23, 2020, 1:09am UTC](https://zola.discourse.group/t/new-global-functions-get-files-or-similar/307/4 "2020-01-23T01:09:55Z")

</div>

If the assets are colocated with a post, why not put them next to the post?

---

<div class="post-metadata">

**Author:** ![simao](https://avatars.discourse-cdn.com/v4/letter/s/e56c9b/32.png) [@simao](https://zola.discourse.group/u/simao)\
**Post date:** [January 23, 2020, 8:10am UTC](https://zola.discourse.group/t/new-global-functions-get-files-or-similar/307/5 "2020-01-23T08:10:02Z")

</div>

Because of the reason you mention here: [Overview | Zola](https://www.getzola.org/documentation/content/overview/#static-assets)

> Depending on your organizational needs, this may be better or worse.

Basically my posts have high resolution photos that I don’t want to commit into git, would be easier if they would be in static in a separate folder so I can back them up and add them to .gitignore easily.

---

<div class="post-metadata">

**Author:** ![kinxiel](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/kinxiel/32/490_2.png) [@kinxiel](https://zola.discourse.group/u/kinxiel)\
**Post date:** [April 13, 2021, 10:01am UTC](https://zola.discourse.group/t/new-global-functions-get-files-or-similar/307/6 "2021-04-13T10:01:35Z")

</div>

Hi,

This thread seems a bit old, but is there a way to do this now in Zola? I would like to render the contents of several directories in static as tables on the same page. Is this possible? Thanks
