Extensionless extends, includes and imports
See original GitHub issueHello
I’m quite new to this community, thus first of all I want to thank all maintainers and contributors for such great templating language.
My proposal is to make file extensions optional in extends, includes and imports.
For example, Instead of
{% extends "layout.nj" %}
use
{% extends "layout" %}
All extensions should be preconfigurated during Environment configuration, or in Loader. If omitted in configuration, it will fall back to default (current, extension-required) behavior.
This will make importing much more intelligent and predictable, while in same time expressive and less verbose. And less typing as bonus.
For example, let’s assume we set our ext
during configuration to ['.j2', '.html']
{% include 'base' %}
Will look in following order for:
base
base.j2
base.html
{% include 'base.j2' %}
Will look in following order for:
base.j2
base.j2.j2
base.j2.html
{% include 'base/' %}
Will look in following order for:
base/index
base/index.j2
base/index.html
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:6 (4 by maintainers)
I dislike this idea a lot. “Explicit is better than implicit” and considering that the file extension can control features like autoescape this is even worse.
Besides that, you could implement this easily using a custom loader if you wanted such behavior. But I’d recommend against it.
I agree with @ThiefMaster, this is less explicit and opens a can of worms around potential edge cases.