Skip to main content

Extended layout system for Jinja

Project description

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 %}

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

jinja_layout-0.5.0.tar.gz (2.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jinja_layout-0.5.0-py3-none-any.whl (3.0 kB view details)

Uploaded Python 3

File details

Details for the file jinja_layout-0.5.0.tar.gz.

File metadata

  • Download URL: jinja_layout-0.5.0.tar.gz
  • Upload date:
  • Size: 2.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.17

File hashes

Hashes for jinja_layout-0.5.0.tar.gz
Algorithm Hash digest
SHA256 80c3120e3726d14b652ff3a1976f6cf44ec568897fcf8bd0c20451e5f03929f0
MD5 1b75e76405d83209cc1d821ba2090afc
BLAKE2b-256 f30d481d4625bd0a5babeb4a60022288d5da535645a26433605c1726b0762df5

See more details on using hashes here.

File details

Details for the file jinja_layout-0.5.0-py3-none-any.whl.

File metadata

File hashes

Hashes for jinja_layout-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1845764ef809541c0c12c0c23e4ff70e259e1e4d789ebeeaaaefba55e09d25b7
MD5 70ed1decddc979b27b36350d32f57ed5
BLAKE2b-256 2c95c4a71f5d33a48b88c58aab67bfe4623aa8b482bb703d8142ee47f0d04a3b

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