Gallery3xFiles
A snippet that outputs a resource's file attachments on the front end. It shows files uploaded in the “Files G3x” tab of the MODX resource editor. Supports filtering, sorting, groups and output with Fenom or standard MODX syntax.
The “Files G3x” tab is enabled by the
gallery3x.files_enablesetting. A file also has the fieldsextra_text,extra_text2,extra_num,extra_date,updatedon.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
resource | int | current resource ID | ID of the resource whose files are output |
resources | string | — | Resource IDs, comma-separated. A negative value excludes a resource (e.g. 5,10,-3) |
parents | string | — | Parent resource IDs, comma-separated. Files of all child resources are output (up to 10 levels deep) |
group | string | — | Filter by a group or several groups, comma-separated. Multi-group is supported |
limit | int | 0 | Maximum number of files. 0 — no limit |
offset | int | 0 | Offset (for pagination) |
sortby | string | position | Sort field: position, name, size, createdon, type |
sortdir | string | ASC | Sort direction: ASC or DESC |
showInactive | int | 0 | Show disabled files. 1 — show |
where | JSON | — | Extra xPDO query conditions in JSON, e.g. {"type":"pdf"} |
tplOuter | string | tpl.Gallery3x.Files.outer | Wrapper chunk for the whole list |
tplItem | string | tpl.Gallery3x.Files.item | Chunk for one file (used with standard MODX syntax) |
fenom | int | 0 | Render with Fenom. Requires pdoTools. With 1 the whole array is passed to tplOuter |
return | string | — | Return data instead of HTML: data — a PHP array, json — a JSON string, ids — an array of IDs |
toPlaceholder | string | — | Save the result to this placeholder instead of outputting it |
debug | int | 0 | Debug mode. With 1 outputs the query parameters and the data of found files |
source | string | — | Media source for the URLs (ID or name). Empty — the record's source |
Fields available in templates
Each item contains these fields:
| Field | Description |
|---|---|
id | Database record ID |
resource_id | MODX resource ID |
file | File name |
path | Relative path to the file folder |
url | Full file URL via the media source |
name | File title (set manually) |
description | File description |
type | File MIME type |
ext | Lowercase file extension (e.g. pdf, zip) |
size | File size in bytes |
size_formatted | Human-readable file size: 1.2 MB, 340 KB, 512 B |
group | Groups separated by || (internal storage format) |
groups_list | Groups separated by commas (handy for output in a template) |
active | Active: 1 — active, 0 — hidden |
position | Sort order number |
createdon | Upload date (Y-m-d H:i:s) |
tplOuter also receives:
| Field | Description |
|---|---|
total | Total number of files found |
first | Data array of the first file (for quick access) |
files | The whole array of files (Fenom only) |
items | Ready HTML of all tplItem (standard syntax only) |
Call examples
Minimal (current resource, standard syntax):
[[!Gallery3xFiles]]
With Fenom:
[[!Gallery3xFiles?
&tplOuter=`tpl.Gallery3x.Files.outer.fenom`
&fenom=`1`
]]
Group filter, limited number:
[[!Gallery3xFiles?
&group=`documents`
&limit=`10`
&sortby=`name`
&sortdir=`ASC`
]]
Files of several resources:
[[!Gallery3xFiles?
&resources=`5,10,15`
&fenom=`1`
&tplOuter=`tpl.Gallery3x.Files.outer.fenom`
]]
Get JSON (for JavaScript or Fenom processing):
[[!Gallery3xFiles?
&return=`json`
]]
Save to a placeholder:
[[!Gallery3xFiles?
&toPlaceholder=`myFiles`
]]
Filtering with where (PDF only):
[[!Gallery3xFiles?
&where=`{"type":"application/pdf"}`
]]