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

{{ if <expression> }}

Conditionals

{{ for <expression> 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>...]]

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 available filters follows.

Filter Name

Effect

car

Returns the first element of a list.

cdr

Returns all but the first element of a list.

even

Returns true iff its input is representable as an even integer.

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.

split

Splits a value into a list by whitespace.

strip

Returns the input string with surrounding whitespace removed.

Substitutions

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.1.1.tar.gz (5.8 kB view details)

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for fett-0.1.1.tar.gz
Algorithm Hash digest
SHA256 fdee4a669e7577c75fac5e62e125fe826ace314b2873a66b0411c925c090afe2
MD5 052066b85f060699eed9063285ba08e6
BLAKE2b-256 484a1e052be97f06b4002330f48b0fea87bce28788eb24d218b897434496a4aa

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