{file}
Writes its rendered content to a file under DATA/ instead of to the page.
Syntax
{file dir='exports', name='orders', ext='csv'} ... {/file}
{file dir='reports', name='daily', ext='html', date, stamp, id=8} ... {/file}
Options
-
dir - The directory below DATA/; none writes in DATA/ itself.
-
name -
The file name,
fileby default. -
ext -
The extension,
extby default. -
date -
Bare option:
_Y-m-dof today added to the name. -
stamp - Bare option: a time stamp added to the name.
-
id - A random suffix of this many characters added to the name.
Description
{file} renders its content as usual - fields, loops, tags - and writes the result to a file instead of to the page; the tag itself shows nothing. The file goes under DATA/: dir= is the directory below it, name= the name (file by default) and ext= the extension (ext by default). An existing file of that name is overwritten.
date adds today's date (_2026-10-08) to the name, stamp a time stamp, and id=8 a random suffix of eight characters, so one run does not overwrite the last.
No name the web server would run is written - .php, .phtml, .phar ... anywhere in it - nor one it reads as configuration, any part starting with a dot such as .htaccess: that is a PAD error, and nothing is written. The tag writes files, so its examples are shown, not run.
Examples
Content to a file
The content renders as usual and goes to DATA/exports/orders.csv instead of the page.
{file dir='exports', name='orders', ext='csv'}
number,customer,total
{orders}{$number},{$customer},{$total}
{/orders}
{/file}
<p>The export is written.</p>
A new name every time
date, stamp and id add the date, a time stamp or a unique id to the name, so one run does not overwrite the last.
{file dir='reports', name='daily', ext='html', date, stamp}
<h1>Report</h1>
{sales}<p>{$region}: {$amount}</p>{/sales}
{/file}
Names that are refused
A name the web server would run or read as configuration is a PAD error, and nothing is written.
{file dir='uploads', name='shell', ext='php'}...{/file} {# .php - refused #}
{file dir='uploads', name='.htaccess', ext='txt'}...{/file} {# a part starting with a dot - refused #}