def get_source(self, environment, template):
try:
- prefix, template = template.split(self.delimiter, 1)
+ prefix, name = template.split(self.delimiter, 1)
loader = self.mapping[prefix]
except (ValueError, KeyError):
raise TemplateNotFound(template)
- return loader.get_source(environment, template)
+ try:
+ return loader.get_source(environment, name)
+ except TemplateNotFound:
+ # re-raise the exception with the correct fileame here.
+ # (the one that includes the prefix)
+ raise TemplateNotFound(template)
class ChoiceLoader(BaseLoader):
:copyright: (c) 2009 by the Jinja Team.
:license: BSD.
"""
-from jinja2 import Template, Environment, DictLoader, TemplateSyntaxError
+from jinja2 import Template, Environment, DictLoader, TemplateSyntaxError, \
+ TemplateNotFound, PrefixLoader
env = Environment()
{% endfor %}
{% endfor %}
""")
+
+
+def test_correct_prefix_loader_name():
+ env = Environment(loader=PrefixLoader({
+ 'foo': DictLoader({})
+ }))
+ try:
+ env.get_template('foo/bar.html')
+ except TemplateNotFound, e:
+ assert e.name == 'foo/bar.html'
+ else:
+ assert False, 'expected error here'