Opened 4 years ago

Closed 4 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

Change History (1)

comment:1 by Mariusz Felisiak, 4 years ago

Resolution: wontfix
Status: newclosed

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.

Note: See TracTickets for help on using tickets.
Back to Top