Skip to content
  1. Extras
  2. PageBuilder
  3. Field types
  4. Free
  5. file

Field file

Version: Free.

Why this type

A field for a PDF, an archive, or another file, not only a picture. After save, the data includes the file name, extension, size, and URL. Files are processed the same way as image.

When to use

  • A PDF price list, a presentation, a file to download
  • An attachment in a form or a button block
  • Any file from MODX media

Tips

In the chunk use {$file.url}, not a file path. Photos alone often fit image.

Similar types

  • image for photos with alt and dimensions
  • url for an external link when nobody uploads a file

Schema

json
{
  "name": "pdf",
  "type": "file",
  "label": "File",
  "description": "PDF or another document",
  "tab": "Content",
  "width": 100,
  "active": true
}

Value

Media object: url, size, title, name, filename, extension, type, and more. A legacy string on read is wrapped as { url }.

Section data

Key pdf in the section data after save enrich (MediaFieldEnricher):

json
{
  "pdf": {
    "url": "assets/files/catalog.pdf",
    "id": 34,
    "path": "assets/files/",
    "filename": "catalog.pdf",
    "extension": "pdf",
    "name": "catalog",
    "title": "catalog.pdf",
    "size": 1048576,
    "type": "pdf"
  }
}
  • A legacy URL string is normalized to { url } on read.

Chunk example

modx
<a href="[[+pdf.url]]" download="[[+pdf.title]]">[[+pdf.title]]</a>
fenom
<a href="{$pdf.url|escape}" download="{$pdf.title|escape}">{$pdf.title|pb_text}</a>

Common properties

For fields with name that are stored in the section data:

KeyTypeRoleCMP
tabstringGroup subtitle in the inspectoryes
width25–100Field width as % of the row (flex)yes
descriptionstringHint under the labelyes
defaultanyInitial value for a new sectionyes
activeboolfalse hides the field in the inspectoryes
requiredboolRequired on publish (draft still saves)yes
  • Also in schema: media object, enrich on save.

See fields overview.

See also