Gallery3xFiles

Gallery3x2 min readPage 8 of 22
On this page 4

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_enable setting. A file also has the fields extra_text, extra_text2, extra_num, extra_date, updatedon.


Parameters

ParameterTypeDefaultDescription
resourceintcurrent resource IDID of the resource whose files are output
resourcesstring—Resource IDs, comma-separated. A negative value excludes a resource (e.g. 5,10,-3)
parentsstring—Parent resource IDs, comma-separated. Files of all child resources are output (up to 10 levels deep)
groupstring—Filter by a group or several groups, comma-separated. Multi-group is supported
limitint0Maximum number of files. 0 — no limit
offsetint0Offset (for pagination)
sortbystringpositionSort field: position, name, size, createdon, type
sortdirstringASCSort direction: ASC or DESC
showInactiveint0Show disabled files. 1 — show
whereJSON—Extra xPDO query conditions in JSON, e.g. {"type":"pdf"}
tplOuterstringtpl.Gallery3x.Files.outerWrapper chunk for the whole list
tplItemstringtpl.Gallery3x.Files.itemChunk for one file (used with standard MODX syntax)
fenomint0Render with Fenom. Requires pdoTools. With 1 the whole array is passed to tplOuter
returnstring—Return data instead of HTML: data — a PHP array, json — a JSON string, ids — an array of IDs
toPlaceholderstring—Save the result to this placeholder instead of outputting it
debugint0Debug mode. With 1 outputs the query parameters and the data of found files
sourcestring—Media source for the URLs (ID or name). Empty — the record's source

Fields available in templates

Each item contains these fields:

FieldDescription
idDatabase record ID
resource_idMODX resource ID
fileFile name
pathRelative path to the file folder
urlFull file URL via the media source
nameFile title (set manually)
descriptionFile description
typeFile MIME type
extLowercase file extension (e.g. pdf, zip)
sizeFile size in bytes
size_formattedHuman-readable file size: 1.2 MB, 340 KB, 512 B
groupGroups separated by || (internal storage format)
groups_listGroups separated by commas (handy for output in a template)
activeActive: 1 — active, 0 — hidden
positionSort order number
createdonUpload date (Y-m-d H:i:s)

tplOuter also receives:

FieldDescription
totalTotal number of files found
firstData array of the first file (for quick access)
filesThe whole array of files (Fenom only)
itemsReady 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"}`
]]