Hello,
I want to add a custom filter to jinja2 and I found that there is a way
to do that through adding a .lib.templatetools.jinja_filters.py module,
so I tryed it...
Every function defined in this module become a filter. But not only
functions :-(, everything imported in this module is included in the
filter's dict !
I'm not sure this was the expected behavior.
Could not it be a .lib.templatetools.py that would contain functions and
a dict named jinja_filters that would contain the filters like in the
config file ? jinja_filters = dict(filter_name=filter_fct, ...) ?
The only change in tg.configuration.app_config.py
change :
# Try to load custom filters module under
app_package.lib.templatetools
try:
filter_package = self.package.__name__ + ".lib.templatetools"
autoload_lib = __import__(filter_package, {}, {},
['jinja_filters'])
autoload_filters = autoload_lib.jinja_filters.__dict__
except (ImportError, AttributeError):
autoload_filters = {}
by :
# Try to load custom filters module under
app_package.lib.templatetools
try:
filter_package = self.package.__name__ + ".lib.templatetools"
autoload_lib = __import__(filter_package, {}, {},
['jinja_filters'])
autoload_filters =
autoload_lib.jinja_filters #
suppress the .__dict__
except (ImportError, AttributeError):
autoload_filters = {}
or
# Try to load custom filters module under
app_package.lib.templatetools
try:
filter_package = self.package.__name__ + ".lib.templatetools"
autoload_lib = __import__(filter_package, {}, {},
['jinja_filters'])
try:
autoload_filters = autoload_lib.jinja_filters.__dict__
except AttributeError:
autoload_filters = autoload_lib.jinja_filters
except (ImportError, AttributeError):
autoload_filters = {}
to support both...
--
You received this message because you are subscribed to the Google Groups
"TurboGears" 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/turbogears?hl=en.