You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guides/pages.md
+21-15Lines changed: 21 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,23 +7,37 @@ Easily create static and dynamic pages with a layout.
7
7
8
8
## Dynamic pages
9
9
10
-
Dynamic pages can use the following formats:
10
+
Pages use the [jinjapy](https://github.com/hyperflask/jinjapy) file format. It combines python code and a [jinja template](#the-page-template). The python code will be executed first on every request, then the template will be rendered.
11
11
12
-
-**jpy**: jinjapy hybrid format that let you execute code before rendering the template
13
-
-**py**: python code only
12
+
The python code is enclosed inside 2 lines containing 3 dashes "---"
14
13
15
-
A jinjapy file contains 2 sections:
14
+
A special [page object](#the-page-object) is available in the python code. Assign values to this object so that they become available in the template.
16
15
17
-
- Some Python code enclosed by lines containg 3 dashes "---"
18
-
- A body containing some Jinja template code
16
+
```jpy
17
+
---
18
+
page.message = "Hello world"
19
+
---
20
+
{{ message }}
21
+
```
19
22
20
-
Both are optional:
23
+
Both the python code or the templates are optional:
21
24
22
25
- If the python code is missing, the file only contains a Jinja template
23
26
- If the python code is left unclosed (the file starts with "---" on a single line followed by some python code), the file has no template
24
27
25
28
The python code has a few global variables injected when executed: `page`, `request`, `abort`, `redirect`, `url_for`, `current_app`, `render_template`.
26
29
30
+
!!! tip
31
+
Pages can also be declared using .py files. In this case they will be pure python modules. Use `page.respond()` to send a response.
32
+
33
+
## The page template
34
+
35
+
Templates are powered by [Jinja](https://jinja.palletsprojects.com/en/stable/).
36
+
37
+
We recommend reading the [Flask templating guide](https://flask.palletsprojects.com/en/stable/templating/).
38
+
39
+
Hyperflask includes built-ins UI components powered by [DaisyUI](https://daisyui.com/). Check out the [Components](/guides/components/#built-in-ui-components) guide.
40
+
27
41
## Content pages
28
42
29
43
No python code will be executed on content pages.
@@ -49,14 +63,6 @@ The URL rule is constructed using the following rules:
49
63
50
64
The placeholder value is available through the [`page` object](#the-page-object) (eg: `page.slug`).
51
65
52
-
## The page template
53
-
54
-
Templates are powered by [Jinja](https://jinja.palletsprojects.com/en/stable/).
55
-
56
-
We recommend reading the [Flask templating guide](https://flask.palletsprojects.com/en/stable/templating/).
57
-
58
-
Hyperflask includes built-ins UI components powered by [DaisyUI](https://daisyui.com/). Check out the [Components](/guides/components/#built-in-ui-components) guide.
59
-
60
66
## Layouts
61
67
62
68
Hyperflask makes managing layouts for your pages easier. Layouts are saved in the *app/layouts* folder. The default layout can be overriden at *app/layouts/default.html*.
0 commit comments