Skip to main content

Add jinja-evaluated types to Lektor

Project description

Lektor Expression Type Plugin

Add jinja-evaluated types, expression and format_expression, to Lektor.

These allow one to define data model fields whose values are Jinja2 expressions.

The Types

Both the expression and format_expression types are evaluated by the jinja template engine.

expression

The expression type is evaluated as a Jinja2 expression.

An example value for this type might be:

this.children.order_by('-pub_date').limit(4)

This would evaluate to a Lektor Query instance.

format_expression

The format_expression type is evaluated as a Jinja2 template. It will always evaluate to a string.

An example value for this type might be:

The blog contains {{ site.get('/blog').count() }} pages.

Installation

Add lektor-expression-type to your project from command line:

lektor plugins add lektor-expression-type

See the Lektor plugin documentation for more information.

Motivating Example

Suppose you want to create an Index data model, for pages which will be used display lists of other pages on your site. You could create a model definition like this (called, perhaps, models/index.ini):

[model]
name = Index Page
label = Index: {{ this.title}}

[fields.title]
label = Title
type = string

[fields.items]
label = Items
type = expression
description = Pages to list on this page

In a particular index page which uses this model, you might set the items field to site.get('/projects').filter(F.tag == 'interesting'), then in the page template (e.g. in templates/index.html) one could reference the items field (e.g. {% for page in this.items %}) to determine which pages to display on the page.

Author

Jeff Dairiki dairiki@dairiki.org

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-expression-type-0.1b1.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

lektor_expression_type-0.1b1-py2.py3-none-any.whl (4.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file lektor-expression-type-0.1b1.tar.gz.

File metadata

  • Download URL: lektor-expression-type-0.1b1.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

File hashes

Hashes for lektor-expression-type-0.1b1.tar.gz
Algorithm Hash digest
SHA256 c794a4a989596c63e16558b954bf5b533b91b4ed31ee32cdc615936560bf8a52
MD5 ffe389e2ab545255b91182f5b6e12d38
BLAKE2b-256 bea61d8b164107e5dd4863af70c6df8960c63d755dad431a2f53c438d806f725

See more details on using hashes here.

File details

Details for the file lektor_expression_type-0.1b1-py2.py3-none-any.whl.

File metadata

  • Download URL: lektor_expression_type-0.1b1-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

File hashes

Hashes for lektor_expression_type-0.1b1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 672950b36b59bd43be31dddbed9b4308cff9ad74b1c03bfa7471b996d657e086
MD5 4b6da75f218a9cfa9dac75c31c50679e
BLAKE2b-256 bedbb0d70b1e54ed3f4eb839e1018dcbf0d5fe469b0fd01325b5f10b8f866863

See more details on using hashes here.

Supported by

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