Skip to main content

plain.elements

Use HTML tags to include HTML template components.

Elements are an alternative to Jinja {% include %} or macros and flow better with existing HTML by using a compatible syntax. They are distinguished from built-in HTML tags by using a capitalized tag name (so <Button> doesn't clash with <button>).

To make a <Submit> element, for example, you would create a template named templates/elements/Submit.html.

<!-- templates/elements/Submit.html -->
<button type="submit" class="btn">
    {{ children }}
</button>

An element can be used in any other template by enabling them with {% use_elements %} and then using the caplitalized tag name.

{% extends "admin/base.html" %}

{% use_elements %}

{% block content %}
<form method="post">
    {{ csrf_input }}
    <!-- Form fields here -->
    <Submit>Save</Submit>
</form>
{% endblock %}

Installation

Install plain.elements from PyPI and add it to your INSTALLED_PACKAGES setting. That's it! The Jinja extension will be enabled automatically.

# settings.py
INSTALLED_PACKAGES = [
    # ...
    "plain.elements",
]

Element attributes

Attributes will be passed through using regular strings or single braces {} for Python variables.

{% extends "admin/base.html" %}

{% use_elements %}

{% block content %}
<form method="post">
    {{ csrf_input }}
    <FormInput field={form.username} placeholder="Username" label="Username" />
    <Submit>Save</Submit>
</form>
{% endblock %}

The attributes are passed to the element as named variables. By default in Plain, you will get an error if you try to use an undefined variable, so Jinja features like |default and is defined are useful for optional attributes.

<!-- templates/elements/FormInput.html -->
<label for="{{ field.html_id }}">
    {{ label }}
</label>
<input
    id="{{ field.html_id }}"
    type="{{ type|default('text') }}"
    name="{{ field.html_name }}"
    value="{{ field.value() or '' }}"
    placeholder="{{ placeholder }}"
    {% if field.field.required %}required{% endif %}
    />

Namespaced elements

Especially for reusable packages, it can be useful to namespace your elements by putting them in a subdirectory of templates/elements/. To use namespaced elements, you need to include the full dot-separated path in your HTML tag.

For example, an element in templates/elements/admin/Submit.html would be used like this:

{% use_elements %}

{% block content %}
<form method="post">
    {{ csrf_input }}
    <admin.Submit>Save</admin.Submit>
</form>
{% endblock %}

Metadata

Release files for plain.elements 0.7.2

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

Source distribution (sdist)

Source distribution for plain.elements 0.7.2
File Size Uploaded Provenance Actions
plain_elements-0.7.2.tar.gz 5.6 kB Without provenance Details for plain_elements-0.7.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for plain.elements 0.7.2
File Interpreter ABI Platform Actions
plain_elements-0.7.2-py3-none-any.whl Python 3 none any Details for plain_elements-0.7.2-py3-none-any.whl

Total release size: 12.2 kB

Release files / plain_elements-0.7.2.tar.gz

Download URL plain_elements-0.7.2.tar.gz
Size 5.6 kB
Tags Source
SHA-256 checksum
How to use checksums
479be1c107eaa8336a754682bbf675a7f6afff19cc3cc1a15dec4fd669c099d3
BLAKE2b-256 checksum
How to use checksums
5a76c8d722c4b2fec8c041dec66af6b5c56e951b60675b9882bd0ac6e136f04f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.7.15

Release files / plain_elements-0.7.2-py3-none-any.whl

Download URL plain_elements-0.7.2-py3-none-any.whl
Size 6.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1821d348a9364d78f29b73df0d2732bfbdcf9a0b94163b7c5feeb872e64838b5
BLAKE2b-256 checksum
How to use checksums
ec28eaeda5556931e7f1cfaccc725903ed4d92c0e7d6db1c237e4c9f01062dc0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.7.15

Security for plain.elements 0.7.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

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