Skip to main content

A Django template tag for wrapping a template block in a reusable enclosing template

Project description

django-wrapwith

A Django template tag for wrapping a template block in a reusable enclosing template.

Provides a block tag called wrapwith which behaves exactly like the built-in include tag, but injects the contents of the block into the included template.

It is intended to make wrapper markup reusable, encouraging you to break your template into "components" which might have a particular enclosing structure but varying contents. It is particularly useful with design systems that provide components (cards, blockquotes, accordians etc) that have reusable structure but arbitrary content.

A toy example: imagine your design includes a box component which has a coloured border, but can contain any other markup inside it.

First, create a wrapper template, wrappers/box.html:

<div style="border: 1px solid {{ bordercol }}">
  {{ wrapped }}
</div>

Note the special {{ wrapped }} variable, which will be replaced with your wrapped content.

Then, in your main page template:

{% load wrapwith %}

<html>
  <body>
    <h1>welcome to my page</h1>

    {% wrapwith "wrappers/box.html" with bordercol="red" %}
      <p>this is inside a red box</p>
    {% endwrapwith %}

    {% wrapwith "wrappers/box.html" with bordercol="green" %}
      <p>this is inside a green box</p>
      <p>and here's another paragraph inside the green box</p>
    {% endwrapwith %}
  </body>
</html>

That's it!

Tested on Python 3 with all currently supported Django versions.

Installation

pip install django-wrapwith

Then add wrapwith to your INSTALLED_APPS.

Code of conduct

For guidelines regarding the code of conduct when contributing to this repository please review https://www.dabapps.com/open-source/code-of-conduct/

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

django-wrapwith-0.0.1.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

django_wrapwith-0.0.1-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file django-wrapwith-0.0.1.tar.gz.

File metadata

  • Download URL: django-wrapwith-0.0.1.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1

File hashes

Hashes for django-wrapwith-0.0.1.tar.gz
Algorithm Hash digest
SHA256 6f27ae1e92b97e7ddd022ff6e1bb82035bd55e37a952c4cbfa15b66e7fb4d30e
MD5 2748c3edde6d6f82b521a1c69b23fbc3
BLAKE2b-256 03e7c478b15376e6e0431e391f77b825a46874cb9e12a459b59a748b4b882f53

See more details on using hashes here.

File details

Details for the file django_wrapwith-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: django_wrapwith-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1

File hashes

Hashes for django_wrapwith-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6714c962810f9d03ffc155c082af5ecc0a8fba64de7f6efac9afeca0c5059390
MD5 f5358f6ef2a73adc4fff271d3885d5c8
BLAKE2b-256 71e986ca55c1fbfe71cda907642f51da55244ff26105f0a2ff96adf9f1423337

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page