Skip to main content

Template fragments for jinja-like engines

API reference | License

Usage:

from template_fragments import filter_template

template_source = """
<html>
    <head>
        <title>Example</title>
    </head>
    <body>
        <div>
        {% fragment content %}
            <!-- content here -->
        {% endfragment %}
        </div>
    </body>
</html>
"""

content_full = filter_template(template_source, "")
content_item = filter_template(template_source, "item")

Usage with Flask and Jinja2:

from template_fragments.jinja import FragmentLoader

app.jinja_loader = FragmentLoader(app.jinja_loader)


@app.route("/")
def get_index():
    return render_template("index.html", ...)


@app.route("/item/<item>")
def get_item(item):
    return render_template("index.html#item", ...)

API reference

template_fragments.split_templates

template_fragments.split_templates(src: str) -> Dict[str, str]

Return all fragments contained in the template

The key "" gives the source template with any fragment directives removed.

template_fragments.filter_template

template_fragments.filter_template(src: str, fragment: str = '') -> str

Return the parts of the template for the given fragment

Parameters:

  • src: the template source
  • fragment: the fragment to return. If fragment = "", removes any fragment directives

template_fragments.split_path

template_fragments.split_path(path: str) -> Tuple[str, str]

Split the fragment from the path

template_fragments.TemplateFragmentError

template_fragments.TemplateFragmentError

Common base class for all non-exit exceptions.

template_fragments.jinja

Jinja specific helpers

template_fragments.jinja.FragmentLoader

template_fragments.jinja.FragmentLoader(base_loader: jinja2.loaders.BaseLoader)

A loader that filters fragments

License

The MIT License (MIT)
Copyright (c) 2022 - 2023 Christopher Prohm

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

Metadata

Release files for template-fragments 23.6.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 template-fragments 23.6.0
File Size Uploaded Provenance Actions
template-fragments-23.6.0.tar.gz 16.2 kB Without provenance Details for template-fragments-23.6.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for template-fragments 23.6.0
File Interpreter ABI Platform Actions
template_fragments-23.6.0-py3-none-any.whl Python 3 none any Details for template_fragments-23.6.0-py3-none-any.whl

Total release size: 21.1 kB

Release files / template-fragments-23.6.0.tar.gz

Download URL template-fragments-23.6.0.tar.gz
Size 16.2 kB
Tags Source
SHA-256 checksum
How to use checksums
a2c26a6033d21ad1cf2548f02e4b44ab6db23ea4c26e47cb3080780d1039561e
BLAKE2b-256 checksum
How to use checksums
e38d75fc70c683de72c65353525343c17791a78772e20446ae43f656406544ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.1 CPython/3.11.4

Release files / template_fragments-23.6.0-py3-none-any.whl

Download URL template_fragments-23.6.0-py3-none-any.whl
Size 4.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
012bdb310dcf3aeb58517dd2f219fec4af96b1a7ea2fddc074e0b884958780a9
BLAKE2b-256 checksum
How to use checksums
809dc2fcfcf84312e85d6c5fe40ec7792384a8205993a30f9fb5f4208b6d77c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.1 CPython/3.11.4

Security for template-fragments 23.6.0

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

This release

23.6.0 This release

2 release files No provenance

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