-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow passing multiple templates to import, just like include #1862
Comments
Note to myself: def _import_common(self, node: t.Union[nodes.Import, nodes.FromImport], frame: Frame) -> None:
func_name = "get_or_select_template"
if isinstance(node.template, nodes.Const):
if isinstance(node.template.value, str):
func_name = "get_template"
elif isinstance(node.template.value, (tuple, list)):
func_name = "select_template"
elif isinstance(node.template, (nodes.Tuple, nodes.List)):
func_name = "select_template"
self.write(f"{self.choose_async('await ')}environment.{func_name}(")
self.visit(node.template, frame)
self.write(f", {self.name!r}).")
if node.with_context:
f_name = f"make_module{self.choose_async('_async')}"
self.write(f"{f_name}(context.get_all(), True, {self.dump_local_context(frame)})")
else:
self.write(f"_get_default_module{self.choose_async('_async')}(context)") |
If this feature request is accepted I'm willing to send a PR 🙂 |
I'm not sure how this might interact with the caching that Jinja does when compiling templates. The behavior and caching of imports already has a lot of old open issues. I'd like old issues like #14, #253, #695, and #916 to be investigated before we decide on adding more complexity to the existing behavior. I'd welcome help with those. |
I think there are many ways a Jinja template can become dynamic enough to make it harder to reason about what it does 😄 Surely two templates included in a single But anyway, I totally understand your points. It's very easy for me to land here, send a PR with a test, and just enjoy a new release, but I completely lack the history behind the features, the complexity in supporting them, and the maintenance cost. So not so easy or enjoyable for you, the maintainer(s) 😅 I'll take a look at the issues you mention, and will try to help if I feel I'm capable and have some time to spare! |
Just like
include
, I would like to be able to pass multiple template paths/names to theimport
tag, so that, quoting the docs, each will be tried in order until one is not missing.This would help in the following case, where instead of defining and adding a test to the env, then conditions inside templates, we could just list the two paths in a single import tag:
Before:
After:
I guess it would need to support the
from ... import ...
syntax too:The text was updated successfully, but these errors were encountered: