Skip to main content

Yet Another Teplate Language (it has been around since 2007)

Project description

Yet Another Template Language

This is the web2py template language described here made available as stand alone package so it can be used anywhere.

Basically it is pure Python within "{{" ... "}}" delimiters and blocks are terminated with "pass" if termination is not obvious. There is no indentation constraints.

For example:

from yatl import render, SPAN

example = """
<div> 
{{ for k in range(num): }}
<span>{{=SPAN(k, _class='number')}} is {{if k % 2 == 0:}}even{{else:}}odd{{pass}}</span>
{{ pass }}
</div>
"""

print(render(example, context=dict(num=10, SPAN=SPAN), delimiters="{{ }}"))

In the example SPAN is an optional helper. Output is escaped by default unless marked up with the XML helper as in {{=XML('1 < 2')}}. Note that the helpers included here are similar but not identical to the web2py ones. They are 99% compatible but the implementation is different.

Any Python expressions is allowed in templates, including function and class defintions:

example = """
{{ def link(x): }}<a href="{{=x}}">{{=x}}</a>{{ pass }}
<ul>
  {{ for k in range(num): }}
  <li>
     {{= link('http://example.com/%s' % k) }}
  </li>
  {{ pass }}
</ul>
"""

print(render(example, context=dict(num=10), delimiters="{{ }}"))

Caching

If you implement a caching reader as the one below, you mak yatl even faster:

CACHE = {}
def reader(filename):
    if filename in CACHE:
        return CACHE[filename]
    with open(filename) as fp;
        CACHE[filename] = content = fp.read()
    return content
      
output = yatl.render(reader(filename), path=path, reader=reader)

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

yatl-20260518.1.tar.gz (21.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yatl-20260518.1-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

File details

Details for the file yatl-20260518.1.tar.gz.

File metadata

  • Download URL: yatl-20260518.1.tar.gz
  • Upload date:
  • Size: 21.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for yatl-20260518.1.tar.gz
Algorithm Hash digest
SHA256 6bc0242308a8f51d79e61d2e05cca846e3ff82bf12c0b412d7a4ab5fea5db2e2
MD5 ce97a75262174f551547bc018e236044
BLAKE2b-256 d869c294d4496d80eef6a106772ff8da097b08a3316fcbe0107ab9aac1f8e506

See more details on using hashes here.

File details

Details for the file yatl-20260518.1-py3-none-any.whl.

File metadata

  • Download URL: yatl-20260518.1-py3-none-any.whl
  • Upload date:
  • Size: 19.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for yatl-20260518.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9539f7d8a4c044b799045050be25f199f1496031dfa42d884c74dd8c59161ec5
MD5 ac912b1d6356c529ee2aa51249f750e3
BLAKE2b-256 d92a6854773ad324c7022190bf5a668289b9d005d393c3411b8defb92cfef004

See more details on using hashes here.

Supported by

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