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.13.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.13-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lektor_chameleon-0.13.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.13.tar.gz
Algorithm Hash digest
SHA256 75e4660f8ecaff2c4bc3fba1c23e22884b9494ef5048e7f51b74d8515751768d
MD5 9bd42ddeabed41217a9747780c9d99f6
BLAKE2b-256 23382bdff02295eabc72311be641884fccde9d8c8235c93adbfc97b678a2482f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lektor_chameleon-0.13-py3-none-any.whl
  • Upload date:
  • Size: 5.4 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.13-py3-none-any.whl
Algorithm Hash digest
SHA256 fafc808b9883bdab60117aa065e6b26364e71752746d48d8108f1e17b2b5001f
MD5 5e93f70723b55648801d3f847c3c2d75
BLAKE2b-256 3b5f280f72111097729957d3d22aac32f94093a676f83b2d1f089bfe384dd278

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