Render content fields with Jinja2.
Project description
lektor-jinja-content
This is a Lektor plugin that allows you to render Jinja2 inside your content fields that are string-like. For example, this means that inside your content fields that are of type string or Markdown, you can write Jinja logic, and access Lektor's Template Context, and has access to all normal Jinja filters, including those provided by other plugins. In a Markdown field (or other field that is rendered - like rst), the Jinja is processed first, then the formatting processor.
With this plugin, you'll have to make sure the content that is rendered is valid Jinja. Jinja syntax erros will throw an exception. Don't forget about the handy {% raw %} {% endraw %}
tags if you want content that is not valid Jinja.
N.B. Using this plugin is rendering many more items with Jinja, and your build process will slow down as a result. As an early benchmark and anecdote, my small website's build time rose from 4.89s to 5.39s even while I actually had no Jinja-Content that needed rendering. I plan on adding the ability to configure this plugin later so that you don't have to run everything through Jinja if you don't want to.
Examples
Querying context: {{ site.get('/').title }}
or {{ this.path }}
Logic:
{% set meaning_of_life, meaning_of_universe = this.life, this.universe %}
{% if meaning_of_life == meaning_of_universe == 42 %}
{% set meaning_of_it_all = meaning_of_life %}
{% else %}
{% set meaning_of_it_all = 'Undefined' %}
{% endif %}
{{ meaning_of_it_all }}
Jinja in Markdown:
[link text]({{ this|url }})
Jinja in reStructuredText:
`link text <{{ this|url }}>`_
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for lektor_jinja_content-0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50e60fed9cb40a97c1ee6a50a45176efaaa7fc53e23c6d50f64fcbadb70d08ae |
|
MD5 | 0727263068dcba34bdadc65a17a7e317 |
|
BLAKE2b-256 | 4efb5f4ce437204a5e6a0a5345d5d595ad1daad8255c8e5ace1057800a509973 |