Skip to main content

Chameleon template support for Lektor.

Project description

lektor-chameleon

lektor-chameleon is a plugin for the Lektor static site generator that makes is possible to write the templates using the Chameleon template engine.

To use the plugin, add it to your project:

$ lektor plugin add lektor-chameleon

Templates must have the .pt file extension.

Usage examples:

<html lang="${ this.alt }">

<h1 tal:content="this.title">Page title</h1>

<span tal:replace="bag('translate', this.alt, 'message')">message</span>

Filters

Lektor filters are available as functions:

For convenience, the following Jinja filters have also been made available as functions:

Usage examples:

<a href="${ url('/') }">Home page</a>

<a href="${ url('/', alt=this.alt) }">link text</a>

<link rel="stylesheet" href="${ asseturl('/static/custom.css') }"/>

<div tal:content="striptags(this.body)">Shortened body text</div>

<div tal:replace="indent(this.body.html, 2)">Page body</div>

<body>
  ${ structure:wordwrap(this.body.html, width=72) }
</body>

Extending templates

In order to have a base template that you want to extend for other templates, you have to use the macro and slot mechanism in Chameleon.

For example, a base template could look like this:

<html>
<head>
  <!-- ... -->
</head>
<body>
  <!-- ... -->
  <div metal:define-slot="content">
    Page content
  </div>
  <!-- ... -->
</body>

Assuming the base template is saved in a file called layout.pt, a template that extends it would look like this:

<html tal:define="layout load:layout.pt" metal:use-macro="layout">

  <div metal:fill-slot="content">
    <p tal:replace="this.body">Page body</p>
  </div>

</html>

Macros

Macros are written using Chameleon's METAL expressions. For example, the pagination macro template created by Lektor quickstart can be implemented as:

<div class="pagination" metal:define-macro="pagination">
  <span tal:condition="not current.has_prev">&laquo; Previous</span>
  <a tal:condition="current.has_prev" href="${ url(current.prev) }">&laquo; Previous</a>

  | <span tal:replace="current.page">Current page</span> |

  <span tal:condition="not current.has_next">Next &raquo;</span>
  <a tal:condition="current.has_next" href="${ url(current.next) }">Next &raquo;</a>
</div>

Note that the macro requires a variable called current which is assumed to hold the current page in the pagination. The template that uses the macro has to define it when calling the macro:

<html
  tal:define="
    layout load:layout.pt;
    pagination load:macros/pagination.pt;
  "
  metal:use-macro="layout">

<div tal:define="current this.pagination"
    metal:use-macro="pagination.macros.pagination">Pagination links</div>

</html>

Also note that the pagination macro template is loaded at the top html tag, so that it can be used in the metal:use-macro clause.

Templating flow blocks

Flow block templates follow the same rules as Jinja flow block templates. The this parameter refers to the block and the record parameter refers to the object that contains the block.

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

lektor_chameleon-0.11.1.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

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

lektor_chameleon-0.11.1-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file lektor_chameleon-0.11.1.tar.gz.

File metadata

  • Download URL: lektor_chameleon-0.11.1.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.11 {"installer":{"name":"uv","version":"0.11.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for lektor_chameleon-0.11.1.tar.gz
Algorithm Hash digest
SHA256 9350c51cf74fb03f59d633213fafe3605754b0e6844eeab775782eed2874948a
MD5 135b284498cee6b6f0c427ff790bf7b1
BLAKE2b-256 a4a094083b350bc9b81a564a23e7444cc9e58b84057ca54768b35420ff2c0db8

See more details on using hashes here.

File details

Details for the file lektor_chameleon-0.11.1-py3-none-any.whl.

File metadata

  • Download URL: lektor_chameleon-0.11.1-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.11 {"installer":{"name":"uv","version":"0.11.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for lektor_chameleon-0.11.1-py3-none-any.whl
Algorithm Hash digest
SHA256 627c5ac50082d25f1b478e2aabbff9b2fc1cada83a1e3f0717771987da35d982
MD5 805fb006e8bcd9b3481237455a7ccd81
BLAKE2b-256 ac223dba535805812e67d355c84969c0d0adbb7fbf43ddf3b576aae3ada46488

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