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
Built Distribution
File details
Details for the file jinja_layout-0.4.0.tar.gz
.
File metadata
- Download URL: jinja_layout-0.4.0.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/6.8.0-40-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e32aed592745250ab8f34eedf9d42c09293628612610ea812ea58748ac677a5c |
|
MD5 | ae9e7d95fc4c7eed889e59e5a413dfc4 |
|
BLAKE2b-256 | a5d2c4437efe22e7071770eeee8c7e6391aa28c382f784c6a6612b55fe352d24 |
File details
Details for the file jinja_layout-0.4.0-py3-none-any.whl
.
File metadata
- Download URL: jinja_layout-0.4.0-py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/6.8.0-40-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e1ddc1ca41b2269dbfbac6164f1040aa1110d55756aa49f5a3049791a1686a7 |
|
MD5 | 55ac04af026d309b7738b185f6f44ec8 |
|
BLAKE2b-256 | 1a1f5b90429b870f112cad050877cd51dc80e6e1c17025927ea8c3b2a4dfd40e |