Opened 5 years ago
Closed 5 years ago
#31996 closed New feature (wontfix)
Template Mixins
| Reported by: | Benjamin Lei | Owned by: | nobody |
|---|---|---|---|
| Component: | Template system | Version: | 3.1 |
| Severity: | Normal | Keywords: | mixins, templates |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Can template mixin support be added to Django? For example, I want to do something similar to:
{% extends 'base.html' %}
{% mixinblock 'entry' %}
<div class="entry">
<h3>{{ title }}</h3><!-- these vars are args that all default to '' or None -->
<div class="author">{{ author }}</div>
<div class="content">{{ content }}</div>
</div>
{% endmixinblock %}
{% block content %}
<!-- For use in Javascript to submit new entries -->
<template id="entry-template">
{% mixin 'entry' %}
</template>
.....
{% for entry in list %}
{% mixin 'entry' title=entry.title author=entry.author content=entry.content %}
{% endfor %}
{% endblock %}
using "include" can do the same, but I'd need a new file for every template when i would sometimes prefer it all in one place
Note:
See TracTickets
for help on using tickets.
Thanks for this report, however you can achieve the same with
{% include %}(as you've already mentioned) or by defining a custom template tag. You can start a discussion on DevelopersMailingList if you don't agree.