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

Uploaded Python 3

File details

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

File metadata

  • Download URL: lektor_chameleon-0.11.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.13 {"installer":{"name":"uv","version":"0.11.13","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.tar.gz
Algorithm Hash digest
SHA256 0d10c511ee460335dc1a55c4ca140245afd0d4b03f6c7f5da8db3054c32df7d3
MD5 39c1b9ac3178f2973323d1f7b6aba0d6
BLAKE2b-256 1313ec1cec10602623589c7fb606cef08f3bef28074614187a233da016688bd3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lektor_chameleon-0.11-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.13 {"installer":{"name":"uv","version":"0.11.13","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-py3-none-any.whl
Algorithm Hash digest
SHA256 069bc0c8bb49e238ff6ccf5b313dab72cfb1c2e5b6043a0d03dc99a069372330
MD5 dcd09f3f57cb8fe782d742b04908b8a8
BLAKE2b-256 a6095cc0a505f517d1f97a44d2fb8c2a4d9df388c56841a578adb21a99ef9492

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