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
Hashes for django-template-mixins-0.3.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 469256e99e69e86fefe1dcce88394700e4db78b7630514362d10ade09e75d687 |
|
MD5 | 19edaa4b9c55bcb91fc52bc89b84d774 |
|
BLAKE2b-256 | 386d475f4d0ad2d5b79dd1c760d9e241bd92a466729fe5edc19661531181aedb |
Hashes for django_template_mixins-0.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3a0c52130e2e7aed6eceb198527e861e7d834b7107b804ee8cd1616aca1e0d7 |
|
MD5 | 77dff2d7f27497e5b82b9d23db9fb419 |
|
BLAKE2b-256 | 9554e49503c15c87271e3f49d499d7159486bffcaad0e3b701e12e8fed520398 |