restructure
This commit is contained in:
parent
ef7661245b
commit
598a10bc28
182 changed files with 342 additions and 336 deletions
|
@ -5,7 +5,7 @@ website: https://jinja.palletsprojects.com/en/3.1.x
|
|||
---
|
||||
|
||||
# Jinja Templates
|
||||
Jinja is a fast, expressive, extensible templating engine. Special placeholders in the template allow writing code similar to [Python](../programming/languages/Python.md) syntax. Then the template is passed data to render the final document. Jinja template files commonly have the `.j2` extension.
|
||||
Jinja is a fast, expressive, extensible templating engine. Special placeholders in the template allow writing code similar to [Python](../dev/programming/languages/Python.md) syntax. Then the template is passed data to render the final document. Jinja template files commonly have the `.j2` extension.
|
||||
|
||||
## Syntax
|
||||
Below is a minimal template that illustrates a few basics using the default Jinja configuration:
|
||||
|
@ -46,10 +46,10 @@ To comment-out part of a line in a template, use the comment syntax which is by
|
|||
```
|
||||
|
||||
### Expressions
|
||||
Jinja allows basic expressions everywhere. These work very similarly to regular [Python](../programming/languages/Python.md); even if you’re not working with [Python](../programming/languages/Python.md) you should feel comfortable with it.
|
||||
Jinja allows basic expressions everywhere. These work very similarly to regular [Python](../dev/programming/languages/Python.md); even if you’re not working with [Python](../dev/programming/languages/Python.md) you should feel comfortable with it.
|
||||
|
||||
#### Literals
|
||||
The simplest form of expressions are literals. Literals are representations for [Python](../programming/languages/Python.md) objects such as strings and numbers. The following literals exist:
|
||||
The simplest form of expressions are literals. Literals are representations for [Python](../dev/programming/languages/Python.md) objects such as strings and numbers. The following literals exist:
|
||||
|
||||
`"Hello World"`
|
||||
|
||||
|
@ -82,7 +82,7 @@ Tuples are like lists that cannot be modified (“immutable”). If a tuple only
|
|||
|
||||
`{'dict': 'of', 'key': 'and', 'value': 'pairs'}`
|
||||
|
||||
A dict in [Python](../programming/languages/Python.md) is a structure that combines keys and values. Keys must be unique and always have exactly one value. Dicts are rarely used in templates; they are useful in some rare cases such as the `xmlattr()` filter.
|
||||
A dict in [Python](../dev/programming/languages/Python.md) is a structure that combines keys and values. Keys must be unique and always have exactly one value. Dicts are rarely used in templates; they are useful in some rare cases such as the `xmlattr()` filter.
|
||||
|
||||
`true` / `false`
|
||||
|
||||
|
@ -131,7 +131,7 @@ This will output the value of `my_variable` if the variable was defined, other
|
|||
```
|
||||
|
||||
##### dictsort(value, case_sensitive: bool = False, by: Literal\["key", "value"]' = 'key', reverse: bool = False)
|
||||
Sort a dict and yield (key, value) pairs. [Python](../programming/languages/Python.md) dicts may not be in the order you want to display them in, so sort them first.
|
||||
Sort a dict and yield (key, value) pairs. [Python](../dev/programming/languages/Python.md) dicts may not be in the order you want to display them in, so sort them first.
|
||||
```
|
||||
{% for key, value in mydict|dictsort %}
|
||||
sort the dict by key, case insensitive
|
||||
|
@ -177,7 +177,7 @@ In most cases it should be more convenient and efficient to use the `%` operator
|
|||
```
|
||||
|
||||
##### groupby(value, attribute: str | int, default: Any | None = None, case_sensitive: bool = False)
|
||||
Group a sequence of objects by an attribute using [Python](../programming/languages/Python.md)’s `itertools.groupby()`. The attribute can use dot notation for nested access, like `"address.city"`. Unlike [Python](../programming/languages/Python.md)’s `groupby`, the values are sorted first so only one group is returned for each unique value.
|
||||
Group a sequence of objects by an attribute using [Python](../dev/programming/languages/Python.md)’s `itertools.groupby()`. The attribute can use dot notation for nested access, like `"address.city"`. Unlike [Python](../dev/programming/languages/Python.md)’s `groupby`, the values are sorted first so only one group is returned for each unique value.
|
||||
|
||||
For example, a list of `User` objects with a `city` attribute can be rendered in groups. In this example, `grouper` refers to the `city` value of the group.
|
||||
```
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue