Opened 4 years ago

Closed 4 years ago

#31915 closed New feature (wontfix)

Allow load template tag before extends tag

Reported by: Jann Haber Owned by: nobody
Component: Template system Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Currently the extends template tag always needs to be the first template tag used in a template (if it is used at all). In the extends tag, it is possible to use the built-in template tags. For example, with Django 3.0, we have been using different base templates depending on if a request was an ajax request or not:

{% extends request.is_ajax|yesno:"base_ajax.html,base.html" %}

Once the is_ajax method is removed from the request objects, this is not possible anymore. A new template tag for "is_ajax" could be created (like {% extends request|is_ajax|yesno... %} ), but it is not possible to load it before extends, since extends always needs to be the first template tag. The only possible workaround I see to achieve the same behaviour, is to create a context processor, however this will be processed for all requests, even the ones that don't need this feature.

All in all, I am requesting to allow load template tags before "extends".

Change History (1)

comment:1 by Carlton Gibson, 4 years ago

Resolution: wontfix
Status: newclosed

I didn't test but you should be able to set the builtins option in your DTL settings
https://docs.djangoproject.com/en/3.1/topics/templates/#django.template.backends.django.DjangoTemplates

Failing that, you'd need to move the is_ajax logic into your view.

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