Django - replacing built-in templatetag by custom tag for a whole site without {% load .. %}

StackOverflow https://stackoverflow.com/questions/1639657

  •  08-07-2019
  •  | 
  •  

Question

I want to replace the standard {% if %} template tag with a "smart if" custom tag from this snippet, because I don't want to write {% load smart_if %} every time. Also, "smart if" will come into core template system very soon.

I forgot where I saw a piece of code that does this. Does anyone know how to replace a built-in templatetag?

Was it helpful?

Solution

Not a full solution to replace the "if" tag, but you can automatically load template tags.

OTHER TIPS

Place this somewhere you know will get run:

from django.template import add_to_builtins
add_to_builtins('mysite.myapp.templatetags.smart_if')

... while placing smart_if.py containing the smart_if code at the appropriate location. This effectively overrides the if tag with "smart if" accross the whole site.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top