PageFactory (Kirby Plugin)

Dir()

Reads specified file system folder and renders a list of found objects.

dir()

Renders the content of a directory.

Arguments

path
Selects the folder to be read. May include an optional selection-pattern (→ 'glob style', e.g. "*.pdf" or "{\*.js,\*.css}") (default: false)
id
Id to be applied to the enclosing li-tag (Default: pfy-dir-#) (default: false)
class
Class to be applied to the enclosing li-tag (Default: pfy-dir) (default: pfy-dir)
target
"target" attribute to be applied to the a-tag. (default: false)
include
[FILES,FOLDERS] Defines what to include in output (default: files)
exclude
Regex pattern by which to exclude specific elements. (default: false)
flags
[REVERSE_ORDER, EXCLUDE_EXTENSION, INCLUDE_PATH, DEEP, HIERARCHICAL, ORDERED_LIST, DOWNLOAD, AS_LINK] Activates miscellaneous modes. (default: false)
prefix
If defined, string will be placed before each element. (default: false)
postfix
If defined, string will be placed behind each element. (default: false)
linkPath
(For internal use only) (default: false)
replaceOnElem
(pattern,replace) If defined, regular expression is applied to each element. Example: remove leading underscore: "^_,''" (default: false)
maxAge
[integer] Maximum age of file (in number of days). (default: false)

Examples

List Files

{{ dir('~/download/') }}
  • sample 1.docx
  • sample 1.pdf
  • sample 2.txt
  • sample spreadsheet.pdf
  • sample spreadsheet.xlsx

→ lists all files in download/.

{{ dir('~/download/', flags: 'DEEP') }}
  • bamboo.jpg
  • breakfast.jpg
  • cactus.jpg
  • sample 1.docx
  • sample 1.pdf
  • sample 2.txt
  • sample spreadsheet.pdf
  • sample spreadsheet.xlsx

→ list all files in download/ including files in sub-foldes.

{{ dir('~/download/', flags: 'HIERARCHICAL') }}
  • sample 1.docx
  • sample 1.pdf
  • sample 2.txt
  • sample spreadsheet.pdf
  • sample spreadsheet.xlsx
    • images/bamboo.jpg
    • images/breakfast.jpg
    • images/cactus.jpg

→ lists files hierarchically.

{{ dir('~/download/', flags: 'DEEP,INCLUDE_PATH') }}
  • download/images/bamboo.jpg
  • download/images/breakfast.jpg
  • download/images/cactus.jpg
  • download/sample 1.docx
  • download/sample 1.pdf
  • download/sample 2.txt
  • download/sample spreadsheet.pdf
  • download/sample spreadsheet.xlsx

→ list all files (including sub-folders) and displays their full path (starting from app-root).

List PDFs for Viewing

{{ dir(    path: '~/download/*.pdf', 
    target: newwin
    flags: 'AS_LINK'
    )
}}

List PDFs for Downloading

{{ dir(    path: '~/download/*.pdf', 
    flags: 'DOWNLOAD'
    )
}}

List all Macros

{{ dir(    path: '~/site/plugins/pagefactory/macros/', 
    replaceOnElem: '^_,', 
    flags: EXCLUDE_EXTENSION, 
    postfix: '()'
    )
}}
  • button()
  • color()
  • dir()
  • img()
  • import()
  • link()
  • list()
  • lorem()
  • nav()
  • prevnextlinks()
  • sitemap()
  • space()
  • span()
  • style()
  • vgap()

Note: the List() macro is implemented by file _List.php (because list is a reserved keyword).
For that reason, we apply replaceOnElem: '_,', which just removes leading underscores.

Miscellaneous Examples

{{ dir('~/download/', flags:EXCLUDE_EXTENSION) }}
  • sample 1
  • sample 1
  • sample 2
  • sample spreadsheet
  • sample spreadsheet
{{ dir('~/download/', flags:'INCLUDE_PATH,ORDERED_LIST,AS_LINK') }}
  1. download/sample 1.docx
  2. download/sample 1.pdf
  3. download/sample 2.txt
  4. download/sample spreadsheet.pdf
  5. download/sample spreadsheet.xlsx