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.12.tar.gz (6.9 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.12-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lektor_chameleon-0.12.tar.gz
  • Upload date:
  • Size: 6.9 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.12.tar.gz
Algorithm Hash digest
SHA256 e3279a23e0579d5bc4f7634725d1c29c37b90812c4101803813e42fc034659fe
MD5 10026111b1bf9d4089ad44a9e23f4620
BLAKE2b-256 a8c1389140a8f1319a86c8c17af3324397c7421184f0c77a54cf52f58f3b36fc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lektor_chameleon-0.12-py3-none-any.whl
  • Upload date:
  • Size: 5.3 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.12-py3-none-any.whl
Algorithm Hash digest
SHA256 381197a6e3907b8ec249d75ec8996dad12c3a3d59a878393a76bc51675b2a463
MD5 227745a92d23896e86a90e2f3ccb3088
BLAKE2b-256 68a3fde4b2ce93f0525f753957f24a51fd856a199e737821d6036140e5578fdb

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