Contains template tags for mixins (in this case, local-template repeatable functions) and components (a separate file that has slots that can be replaced).
Project description
A template filter that allows you to define and use mixins.
Installation
In your Django project, run:
pip install django-template-mixins
and add mixin_templatetag to your INSTALLED_APPS setting:
INSTALLED_APPS = [ ..., 'mixin_templatetag' ]
and from there you can use it as follows:
{% load mixins %}
{% mixin foo %}
<div>
<div>{{ name }}</div>
<div>{{ description }}</div>
</div>
{% endmixin %}
{% block content %}
...
{% mix foo with name="hello" description="world" %}
...
{% endblock %}
If you want to use components instead, note that the feature is EXPERIMENTAL + there is a restriction that components can’t extend or include another file.
Here’s an example of using components:
component.html:
<body>
{% slot foo %}
<div>DEFAULT_FOO{{ some_var }}</div>
{% endslot %}
{% slot bar %}
<div>DEFAULT_BAR</div>
{% endslot %}
</body>
content.html:
{% component 'component.html' with some_var=':(' %}
{% slot bar %}
my way
{% endslot %}
{% endcomponent %}
Why django-template-mixins?
Currently in Django, if you want to repeat a block multiple times in separate blocks / areas in the same block, you have to create a separate file. The worst part is that these extracted bits of template tend to be single purpose - you aren’t likely to need it anywhere else besides that first template.
Mixins allow you to keep things in one place and allows you to avoid DRY.
I added in components (EXPERIMENTALLY) to the mix because it was requested, and after thinking about it for awhile it seemed like a useful feature that I would also want. From my basic tests it seems to work.
Reporting bugs
You can report bugs in https://github.com/benlei/django-template-mixins/issues.
If you believe you’ve found a bug, please try to identify the root cause and write up some sample code on how to reproduce it.
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django-template-mixins-0.3.1.tar.gz.
File metadata
- Download URL: django-template-mixins-0.3.1.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
72bc6625b1142ac36ab6dd739481c3b420df32112bf39d1cbc13ce3393cd3381
|
|
| MD5 |
f3ab672fa6a941d48292bb2eca0d3352
|
|
| BLAKE2b-256 |
4160f0d404d85f113c34c53737803e63030195eae47f4832901e91d260e3ea20
|
File details
Details for the file django_template_mixins-0.3.1-py3-none-any.whl.
File metadata
- Download URL: django_template_mixins-0.3.1-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f4d6902fcce1f4bd5a3d1248e279605db159b66cf494f36e5ad1433560148d58
|
|
| MD5 |
40891babca49fd15da0860ac30763116
|
|
| BLAKE2b-256 |
fcf1e5d2d4626a33bac980cf550d34bdf2c7dc499b7935749fe5f007f4a80a38
|