get_files
Retrieves a list of files.
{{ get_files }}
Fetches any files from anywhere. Great for photo galleries or anything you can imagine. The tag loop with return filenames assigned to {{ file }}
.
Sample Usage
{{ get_files in="assets/img" extension="jpg" file_size="< 250K" }}
<img src="{{ file }}" />
{{ /get_files }}
Parameters
sort_by
new in 1.7!
Allows you to specify what attribute sort the file list on. Options are file
, type
, size
and random
.
sort_dir
new in 1.7!
Sets the direction to arrange the list, either ascending (asc
, default) or descending (desc
).
limit
new in 1.7!
If set, limits the the maximum number of files to display. The list is limited after the sorting has been performed.
match
Restrict files through use of globs, strings, or regexes
{{ get_files match="/header/" }}
exclude
The direct inverse of match
. Excludes files based on globs, strings, or regexes
{{ get_files exclude="/thumbnail/" }}
extension
Find files by file extensions.
{{ get_files extension="png" }}
in
The folder you wish to fetch files from. Can be used recursively to drill through multiple folder levels.
You can specify multiple folders by separating them with pipes |
. New in 1.7!
{{ get_files in="assets/img" }}
not_in
Exclude folders from being traversed.
{{ get_files not_in="assets/img/secrets" }}
file_size
Restrict by size using any of the following comparison operators: >, >=, <, <=, ==, !=.
{{ get_files file_size="< 500K" }}
file_date
Restrict by last modified dates. The target value can be any date supported by PHP’s strtotime function.
{{ get_files file_date="since Monday" }}
depth
By default, Get Files recursively traverse directories. This lets you restrict the depth it will traverse.
{{ get_files depth="== 0" }}
{{ get_files depth="< 3" }}
Variables
The follow variables are available inside your {{ get_files }}
tag loop results.
Variable | Description |
---|---|
{{ file }} |
full URL to file (/assets/img/photo.jpg) |
{{ filename }} |
the filename of the file (photo.jpg) new in 1.7 |
{{ extension }} |
the file’s extension (pdf) new in 1.7 |
{{ size }} |
pretty filesize formatting (45 KB) new in 1.7 |
{{ size_bytes }} |
filesize in bytes new in 1.7 |
{{ size_kilobytes }} |
filesize in kilobytes new in 1.7 |
{{ size_megabytes }} |
filesize in megabytes new in 1.7 |
{{ size_gigabytes }} |
filesize in gigabytes new in 1.7 |
{{ is_image }} |
boolean true or false if the file is an image new in 1.7 |