On Sat, May 2, 2009 at 8:44 PM, Rex <[email protected]> wrote:
>
> I have a module called myfilters.py that contains my custom filters.
> Is there some way around putting the command "{% load myfilters %}" in
> every template I want to use a custom filter in? I tried putting the
> load command in a base template, but templates that inherit from this
> one don't appear to inherit the filters that get loaded. Is this
> correct?
>
Yes this is correct. The way the templates work is that each block is a
separate node and the context that they are rendered in is separate as well.
If you wish to add a group of filters or template tags to built ins, there
is a hook that lets you do this. django.template.add_to_builtins lets you
add a module to built in template tags and filters in every template. I
wouldn't recommend this however, because it does slow down performance a
touch, on load time and every time a tag needs to be looked at and if there
happens to be an error in the tags that you added to built ins every
template on every page will throw an error instead of just the ones you
imported that library in.
You might also want to look at context processors, they allow you to place
variables in the context that you might want on every template.
Hope that helps,
Michael
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---