{output}
Switches how the running request answers - a web page, the console, a file, a download, JSON or CSV.
Syntax
{output 'type'}
Parameters
-
type -
One of
web,console,file,download,jsonorcsv.
Description
{output 'type'} sets $padOutputType for the rest of the request and loads that type's settings over the current ones. It decides how the whole response is delivered once the page has finished, not what happens at the place of the tag - so it can stand anywhere in the template. It does the same as $padOutputType set in _config/config.php or in the page's PHP, from the template.
-
web- the default: the rendered page is sent to the browser. -
console- the rendered text written for the command line. -
file- the rendered page is written to a file underDATA/, named by the$padFile*settings, and the request goes on with another page. -
download- the rendered page is sent as an attachment, named the same way. -
jsonandcsv- what the template rendered is replaced by the page's data: the variables its PHP names in$padExpose, as one JSON object, or the first of them that is a list as CSV with a header row.
The same JSON or CSV answer comes without the tag for ?page&padFormat=json (or csv) and for an Accept: application/json header - and then the template is not rendered at all. A page that exposes nothing has nothing to answer as JSON, and CSV needs an exposed list; both are errors.
A type that is not one of the six is an error, and the mode stays as it was. Because it changes the whole response, the examples here are shown but not run.
Examples
Answer JSON
The page answers the variables its PHP names in $padExpose as one JSON object; this template text is not sent.
{output 'json'}
<p>Shown only to a reader of the template.</p>
A download
The rendered page goes to the browser as an attachment instead of being shown.
{output 'download'}
<h1>Invoice {$number}</h1>
<p>Total: {$total | money}</p>
See also
- {flush} Sends the page rendered so far to the browser at once, so it can load the stylesheets while a slow part below renders.
- {tidy} Rewrites the HTML it wraps as tidied, indented markup through PHP's tidy extension.
- {page} Renders another page of the application - its PHP and its template - in place of the tag.