Skip to main content

A fast indentation-preserving template engine.

Project description

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> }}

Substitutions

{{ `foo` <expression> }}

Substitutions

{{ format <name> }}

Metaformatting

{{ if <expression> }}

Conditionals

{{ for <name> in <expression> }}

Loops

{{ else }}

{{ end }}

Block termination

{{ # <comment> }}

Comments

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

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fett-0.3.0.tar.gz (7.0 kB view details)

Uploaded Source

File details

Details for the file fett-0.3.0.tar.gz.

File metadata

  • Download URL: fett-0.3.0.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for fett-0.3.0.tar.gz
Algorithm Hash digest
SHA256 62d7164c8cef12ecc045e7ea7f90f37703fd051c99cb92714754dbf3f9412421
MD5 58f175bb87c7bfaf7e409107f3d9a2b8
BLAKE2b-256 ea41e0bf3291a7eedfea28f1d5b80b80c77ab643fec38e57cabf5473b8c6f090

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page