@ -30,7 +30,9 @@ It is most likely Python isn't installed. You can [download it, and find install
### Jinja
### Jinja
```python
pip3 install jinja2
pip3 install jinja2
```
## Running the script
## Running the script
@ -38,7 +40,7 @@ Running the script should result in the folder of the script: `index.html` this
*When using the terminal*: The script can be ran by first using `cd` to move into the folder of the script. The easiest way is typing `cd` and a space and then drag and drop the folder onto the terminal. Then press enter. Once you are in the folder, type:
*When using the terminal*: The script can be ran by first using `cd` to move into the folder of the script. The easiest way is typing `cd` and a space and then drag and drop the folder onto the terminal. Then press enter. Once you are in the folder, type:
```
```bash
python3 render-template.py
python3 render-template.py
```
```
@ -49,7 +51,7 @@ Pages using paged.js *and* an external styles file need to be opened through a l
It is quite possible your editor has this functionality built in and it is perfectly fine to use that.
It is quite possible your editor has this functionality built in and it is perfectly fine to use that.
Python also has a simple server built in. To start it, first `cd` into the folder of your project. Then run:
Python also has a simple server built in. To start it, first `cd` into the folder of your project. Then run:
```
```bash
python3 -m http.server
python3 -m http.server
```
```
@ -68,13 +70,13 @@ Open a webbrowser and open the address <http://0.0.0.0:8000/> to see the generat
It is possible to use a different template by adjusting the `env.get_template` replace for example the line:
It is possible to use a different template by adjusting the `env.get_template` replace for example the line:
@ -89,13 +91,13 @@ Extensive documentation on the jinja templating engine can be found here: <https
The first way to extend the template is by providing extra variables, this can be done by providing extra keyword arguments in the template render call. With the python line below a placeholder `extra_placeholder` is added and becomes available in the template:
The first way to extend the template is by providing extra variables, this can be done by providing extra keyword arguments in the template render call. With the python line below a placeholder `extra_placeholder` is added and becomes available in the template:
```
```python
rendered_template = template.render(template_placeholder="world", extra_placeholder="More information in the template")
rendered_template = template.render(template_placeholder="world", extra_placeholder="More information in the template")
```
```
In the template it is possible to refer to this placeholder with the `{{ }}` syntax, so:
In the template it is possible to refer to this placeholder with the `{{ }}` syntax, so:
```
```jinja
{{ extra_placeholder }}
{{ extra_placeholder }}
```
```
@ -105,19 +107,19 @@ Just like python jinja supports [loops](https://jinja.palletsprojects.com/en/3.1
It is important to understand that jinja places data in a template. It is not intended to generate data. To work with loops jinja needs a list (or actually an iterable), data it can loop over. In jinja the start of a loop is indicated with `{% for %}` the end of the loop with `{% endfor %}`
It is important to understand that jinja places data in a template. It is not intended to generate data. To work with loops jinja needs a list (or actually an iterable), data it can loop over. In jinja the start of a loop is indicated with `{% for %}` the end of the loop with `{% endfor %}`