Overview
Example
import fett
fett.Template('''{{ for customer in customers }}
{{ if i even }}
Even: {{ customer.name }}
{{ else }}
Odd: {{ customer.name }}
{{ end }}
{{ else }}
No customers :(
{{ end }}''').render({'customers': [
{'name': 'Bob'},
{'name': 'Elvis'},
{'name': 'Judy'}
]})
Syntax
Tag Format |
Description |
|---|---|
{{ <expression> }} |
|
{{ `foo` <expression> }} |
|
{{ format <name> }} |
|
{{ if <expression> }} |
|
{{ for <name> in <expression> }} |
|
{{ else }} |
|
{{ end }} |
Block termination |
{{ # <comment> }} |
Spaces between tag opening/closing delimiters are optional.
Expressions
An expression is given for Substitutions, Conditionals, and Loops.
Expressions take the following form:
<name>[.<subfield>…] [<filter> [<filter2>…]]
Instead of specifying a field path, you can start an expression using a string literal:
<literal> [<filter> [<filter2>…]]
You can use filters to modify a single value in simple ways. For example, the loop iteration counter i counts from 0, but users often wish to count from 1. You can obtain a count-from-1 value with the expression i inc.
The full list of filters:
Filter Name |
Effect |
|---|---|
car |
Returns the first element of a list. |
cdr |
Returns all but the first element of a list. |
dec |
Decrements a value representable as an integer by one. |
even |
Returns true iff its input is representable as an even integer. |
escape |
Encodes &, <, >, “, and ‘ characters with HTML entities. |
inc |
Increments a value representable as an integer by one. |
len |
Returns the length of a list. |
not |
Returns the inverse of a boolean. |
odd |
Returns true iff its input is representable as an odd integer. |
negative |
Returns true iff its input is representable as an integer < 0. |
positive |
Returns true iff its input is representable as an integer > 0. |
split |
Splits a value into a list by whitespace. |
strip |
Returns the input string with surrounding whitespace removed. |
striptags |
Remove HTML tags from a value. |
timesNegOne |
Returns int(input) * -1 |
zero |
Returns true iff the input is zero |
Filter Name |
Effect |
|---|---|
upperCase |
Returns a Unicode-aware uppercase version of the input. |
lowerCase |
Returns a Unicode-aware lowercase version of the input. |
Filter Name |
Effect |
|---|---|
add(n) |
Increments a value representable as an integer by n. |
minus(n) |
Decrements a value representable as an integer by n. |
equal(value) |
Returns true iff a value equals the given value. |
lessThan(n) |
Returns true iff n < the given value. |
lessThanOrEqual(n) |
Returns true iff n <= the given value. |
greaterThan(n) |
Returns true iff n > the given value. |
greaterThanOrEqual(n) |
Returns true iff n >= the given value. |
Substitutions
Metaformatting
Conditionals
Loops
Comments
Metadata
Release files for fett 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| fett-0.4.0.tar.gz | 6.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fett-0.4.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.7 kB
Release files / fett-0.4.0.tar.gz
| Download URL | fett-0.4.0.tar.gz |
|---|---|
| Size | 6.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
56912ad93cf537a450b4fb15ee97aedd97acf81a14e48375c523fffdeb182986
|
|
BLAKE2b-256 checksum How to use checksums |
13c362d07518d5f12673b6894211f4320046987e7a2d5664a73337d521957a04
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.1 CPython/3.10.7 Linux/5.15.74-3-MANJARO
|
Release files / fett-0.4.0-py3-none-any.whl
| Download URL | fett-0.4.0-py3-none-any.whl |
|---|---|
| Size | 6.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
01b43baf8c1b2520f52bc1f8e49cd0a08e9290292c8be5acc1c54bdc530e75cf
|
|
BLAKE2b-256 checksum How to use checksums |
46e69c2150926e5aea200ac862fb7b7d9f14627c8354e667cd82aa15e2fd4343
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.1 CPython/3.10.7 Linux/5.15.74-3-MANJARO
|