Overview
What you do with this tag is up to you. It's that odd, multi-tool you don't have a use for...until you need it desperately. If you need to do stuff with listing files and their meta data, this might be the thing you're looking for.
Don't forget about assets though, they're a much more robust and controlled aspect of Statamic.
Example
Here's a few examples of what you can do with the get_files
tag.
List non-asset images in the site's design resources
{{ get_files in="public/img/brand" }} <img src="{{ file }}" class="w-1/3">{{ /get_files }}
<s:get_files in="public/img/brand"> <img src="{{ $file }}" class="w-1/3"></s:get_files>
List the zip files in a web-inaccessible directory
<table> <thead> <tr> <th>File</th> <th>Size</th> <th>Last Modified</th> </tr> </thead> <tbody> {{ get_files in="secure/downloads" }} <tr> <td>{{ basename }}</td> <td>{{ size }}</td> <td>{{ last_modified }}</td> </tr> {{ /get_files }} </tbody></table>
<table> <thead> <tr> <th>File</th> <th>Size</th> <th>Last Modified</th> </tr> </thead> <tbody> <s:get_files in="secure/downloads"> <tr> <td>{{ $basename }}</td> <td>{{ $size }}</td> <td>{{ $last_modified }}</td> </tr> </s:get_files> </tbody></table>
Parameters
in|from
The directory to find files in relative to the public/
directory. Example: in="img/brand"
depth
The depth of subdirectories to recursively look through. Default: 1
(no recursion).
not_in
Filter by excluding from a subdirectory or subdirectories. You may use regex, and will be matched against the file path without a leading slash. For example: not_in="img/(brand|logos)"
file_size
Filter by file size using one of the following comparison operators. >, >=, <, <=, ==, !=. For example: file_size="< 500K"
ext|extension
Filter by file extension. You may pipe delimit multiple extensions. Example: ext="jpg|png"
.
include|match
Filter files by a regular expression. Matches will be kept.
exclude
Exclude files by a regular expression. Matches will be removed.
file_date
Filter by last modified dates. The target value can be any date supported by PHP’s strtotime function.
limit
Limit the total results returned.
offset
The number of entries the results should by offset by.
sort
Sort the listing by type
(file extension), size
, last_modified
, or random
.
Variables
Variable | Type | Description |
---|---|---|
file |
string |
The filename path relative to your project root. |
filename |
string |
The filename part of the path. The |
basename |
string |
The basename part of the path. The |
extension |
string |
The file extension. Example: |
size |
string |
The file size in a human readable format. Example: |
size_bytes|size_b |
integer |
The file size in bytes. |
size_kilobytes|size_kb |
integer |
The file size in kilobytes. |
size_megabytes|size_mb |
integer |
The file size in megabytes. |
size_gigabytes|size_gb |
integer |
The file size in gigabytes. |
is_image |
boolean |
Whether the file is an image. |
last_modified |
Carbon |
The last modified date of the file. |