Liquid code to list files from a particular directory

I’m not sure what I’m doing wrong … ( just starting out with liquid code)

I need to list all documents in a particular file directory: In my case (/partner/festivalsandevents)

From the liquid documentation - I thought something like the code below would have listed all files for me …

{% component type: “api”, resource: “File System”, folder: “/partner/festivalsandevents”, collectionVariable: “myfiles” %}

    {% for i in myfiles.items %}
  • {{i['url']}}
  • {% endfor %}

But it didn’t work? Any ideas why?
FYI … the directory /partner/festivalsandevents just contains some PDF files

Hi @Adele_Taylor

It seems correct what you have done. I tested this a while back on a trial/test site, and that is running 5.0.0 now. I know I had this code working, and it doesn’t anymore. Just tested the exact same code on a 4.12.0 site and it works there. Both sites have the same “beta features” settings.

@alex.n - Will somebody from the team check this and see if you guys can replicate it, or has something changed in the API in 5.0.0 ? :slight_smile:

1 Like

Hi Guys,

Thanks for reporting the bug. We’ll be working on fixing this.

Seems the Bug is fixed now with v5.01. Thank you all!

By the way … just thought this snippet might be useful for someone new to liquid (like me).
{{i[‘url’]}} list the full url path eg /Content/Pages/myfilename.pdf
But if you only one to show the file name (minus the full directory path) use
{{i[‘url’] | split: ‘/’ | last }} and it will show only myfilename.pdf

So if you paste the code below and update what is in CAPS to suit, you will get a list of files in your chosen directory, that have hyperlinks for download.

{% component type: "api", resource: "File System", folder: "/Content/Pages/YOURDIRECTORY/", collectionVariable: "YOURCOLLECTIONFILENAME" %}
<p> <a href="{{i['url']}} " >{{i['url'] | split: '/' | last }} </a>  </p>
{% endfor %}

Great that this is fixed :+1:
And thanks for the code snippet @Adele_Taylor, sure that will come in handy for other partners :slight_smile:

For any one that is interested … there was an update and the above snippet no longer works. It now needs to include ?downloadable=1 for the files to be downloadable …so
<a href="{{i['url']}}?downloadable=1" rel="noopener noreferrer" target="_blank" title="">{{i['url'] | split: '/' | last }} </a>