Radical Design Course by Jack McDade

From the creator of Statamic

Learn how to make your websites standout and be remembered.

This course is the most refreshing take on teaching design that I've come across.

— Mikaël Sévigny, Developer

Get Files Tag

The ultimate 🇨🇭Swiss Army Knife doing-stuff-with-files feature. With the get_files tag you can scan and display data on files in any directories inside your local filesystem.

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

string

The directory to find files in relative to the public/ directory. Example: in="img/brand"

depth

integer

The depth of subdirectories to recursively look through. Default: 1 (no recursion).

not_in

string

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

string

Filter by file size using one of the following comparison operators. >, >=, <, <=, ==, !=. For example: file_size="< 500K"

ext|extension

string

Filter by file extension. You may pipe delimit multiple extensions. Example: ext="jpg|png".

include|match

regex

Filter files by a regular expression. Matches will be kept.

exclude

regex

Exclude files by a regular expression. Matches will be removed.

file_date

string

Filter by last modified dates. The target value can be any date supported by PHP’s strtotime function.

limit

integer

Limit the total results returned.

offset

integer

The number of entries the results should by offset by.

sort

string

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 neon in path/to/neon.jpg

basename

string

The basename part of the path. The neon.jpg in path/to/neon.jpg

extension

string

The file extension. Example: jpg or zip.

size

string

The file size in a human readable format. Example: 1.24 MB.

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.

Docs feedback

Submit improvements, related content, or suggestions through Github.

Betterify this page →