mozilla / nunjucks

A powerful templating engine with inheritance, asynchronous control, and more (jinja2 inspired)
https://mozilla.github.io/nunjucks/
BSD 2-Clause "Simplified" License
8.57k stars 639 forks source link

remove whitespaces from extends parameters. #1210

Open mhayk opened 5 years ago

mhayk commented 5 years ago

When you try to extends a template with whitespace like: {% extends "_layouts/default.njk " %} the parser throw the error: Error: template not found: _layouts/default.njk

fdintino commented 5 years ago

I don't think this is a bug. Jinja2 has the same behavior.

>>> from jinja2 import DictLoader, Environment
>>> env = Environment(loader=DictLoader({
...    'base.html': '{% block foo %}FOO{% endblock %}',
... }))
>>> env.from_string('{% extends "base.html" %}').render()
'FOO'
>>> env.from_string('{% extends "base.html " %}').render()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
[...]
jinja2.exceptions.TemplateNotFound: base.html

Why not just remove the extra space from your template?

mhayk commented 5 years ago

@fdintino this helps the developer to avoid spend a lot of time trying to figure out that it has added a space. This is a smart way to continue rendering the page.