Skip to content

Commit 4a78a9e

Browse files
authored
Merge pull request #53 from tbreuss/develop
Add route handler doc
2 parents eb785bb + 000af42 commit 4a78a9e

1 file changed

Lines changed: 40 additions & 1 deletion

File tree

website/routes/doc.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,23 +281,62 @@ Zack! is currently delivered with the following route handlers:
281281
File extensions: htm, html \
282282
Response content-type: text/html
283283

284+
The content of the HTML file is taken.
285+
The Twig layout is determined via the layout comment `<!-- layout: my-layout.html.twig -->` in the HTML content.
286+
The page title is determined by the H1-H3 headings in the HTML content.
287+
The layout is applied and output together with the page title and the HTML content.
288+
284289
#### JSON Route Handler
285290

286291
File extension: json \
287292
Response content-type: application/json
288293

294+
The content of the JSON file is read and output.
295+
289296
#### Markdown Route Handler
290297

291298
File extensions: markdown, md \
292299
Response content-type: text/html
293300

301+
The content of the Markdown file is taken.
302+
The markdown is converted to HTML using one of the following Composer packages:
303+
304+
- league/commonmark
305+
- michelf/php-markdown
306+
- erusev/parsedown
307+
308+
The Twig layout is determined via the layout comment `<!-- layout: my-layout.html.twig -->` in the HTML content.
309+
The page title is determined by the H1-H3 headings in the HTML content.
310+
The layout is applied and output together with the page title and the HTML content.
311+
294312
#### PHP Route Handler
295313

296314
File extension: php \
297-
Response content-type: text/html
315+
Response content-type: text/html, application/json, or other
298316

299317
The content-type of the response can be set explicitly in a PHP route handler.
300318

319+
##### Echoing Content
320+
321+
The echoed content of the PHP file is taken.
322+
323+
If the HTML content contains an `html` element or a `Doctype`, the HTML content is output as it is.
324+
325+
Otherwise the Twig layout is determined via the layout comment `<!-- layout: my-layout.html.twig -->` in the HTML content.
326+
The page title is determined by the H1-H3 headings in the HTML content.
327+
The layout is applied and output together with the page title and the HTML content.
328+
329+
##### Returning Response
330+
331+
If you want finer control over the HTTP response, you can return a string, an array or a `Symfony\Component\HttpFoundation\Response` object.
332+
333+
If the return value is a string, it is output as HTML with the content type `text/html`.
334+
335+
If the return value is an array, it is JSON encoded and output with the content-type `application/json`.
336+
337+
If the return value is a `Symfony\Component\HttpFoundation\Response` object, it is output unchanged together with the underlying content type.
338+
There are several response subclasses to help you return JSON, redirect, stream file downloads and more.
339+
301340
### Events
302341

303342
#### Zack! Events

0 commit comments

Comments
 (0)