Skip to main content

Jinja Layout

Easier layouts for Jinja templates.

Installation

pip install jinja-layout

Usage

The jinja_layout.LayoutExtension needs to be added to your environment:

from jinja2 import Environment, PackageLoader

env = Environment(loader=PackageLoader(__name__, 'templates'))
env.add_extension('jinja_layout.LayoutExtension')

Jinja-layout introduces the use_layout directive. There are two optional arguments:

  • a template name to extend from (default: "layout.html")
  • the name of the default block to override (default: "content")

You can change the default layout template using the defaut_layout attribute on your environment and the default block name using the default_layout_block attribute.

This directive is similar to Jinja's extends directive but does not require the use of blocks. The content which is not used in blocks, will be automatically wrapped in a block. The name of this block is defined by the second argument of the directive.

Example

Let's consider the following layout saved as layout.html:

<html>
  <head>{% block head %}{% endblock %}</head>
  <body>{% block content %}{% endblock %}</body>
</html>

Basic layout example:

{% use_layout %}
hello world

Overriding the header block:

{% use_layout %}
{% block head %}<title>example</title>{% endblock %}
hello world

Using blocks all the way:

{% use_layout %}
{% block head %}<title>example</title>{% endblock %}
{% block content %}hello world{% endblock %}

Metadata

Release files for jinja-layout 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jinja-layout 0.5.0
File Size Uploaded
jinja_layout-0.5.0.tar.gz 2.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jinja-layout 0.5.0
File Interpreter ABI Platform
jinja_layout-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 5.3 kB

Release files / jinja_layout-0.5.0.tar.gz

Download URL jinja_layout-0.5.0.tar.gz
Size 2.3 kB
Tags Source
SHA-256 checksum
How to use checksums
80c3120e3726d14b652ff3a1976f6cf44ec568897fcf8bd0c20451e5f03929f0
BLAKE2b-256 checksum
How to use checksums
f30d481d4625bd0a5babeb4a60022288d5da535645a26433605c1726b0762df5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.17

Release files / jinja_layout-0.5.0-py3-none-any.whl

Download URL jinja_layout-0.5.0-py3-none-any.whl
Size 3.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1845764ef809541c0c12c0c23e4ff70e259e1e4d789ebeeaaaefba55e09d25b7
BLAKE2b-256 checksum
How to use checksums
2c95c4a71f5d33a48b88c58aab67bfe4623aa8b482bb703d8142ee47f0d04a3b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.17

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

0.4.0

2 release files

0.3

1 release file

0.2

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page