Support ChainableUndefined for jinja2 Environment
See original GitHub issueJinja 2.11 supports setting undefined
option on an Environment
to ChainableUndefined
. This allows the default
filter to work on nested elements and attributes.
Arguably this could be a better default behavior for use in copier
, but regardless of the default it would be nice to be able to configure this in copier.yml
. The _envops
configuration exists, but there’s no way to set undefined
to a python class in that YAML file (that I know of at least), so I think either a specific config value would be needed, or someway to lookup a class for the undefined
key. I’m not sure which is the best or preferred way, but would like to turn this on to make the templates that use nested configuration easier to set their defaults.
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
API — Jinja Documentation (3.0.x)
Returns a list of templates for this environment. This requires that the loader supports the loader's list_templates() method.
Read more >How to set the Jinja environment variable in Flask?
from flask import Flask from jinja2 import ChainableUndefined app = Flask(__name__) app.jinja_options["undefined"] = ChainableUndefined.
Read more >jinja2.environment.Environment — Jinja2 API - GitHub Pages
The core component of Jinja is the Environment . It contains important shared variables like configuration, filters, tests, globals and others. Instances of ......
Read more >Python Examples of jinja2.ChoiceLoader - ProgramCreek.com
Environment (loader=jinja2. ... attach the service to the loop self.loop.service = self. Example #19 ... ChainableUndefined loaderset = [jinja2.
Read more >[ansible-project] Ansible module "template" support for Jinja2 ...
However, I don't know how to pass this new "ChainableUndefined" class to > the parameter "undefined" in the Jinja2 environment via the ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes, sorry I should have included one.
This doesn’t have great support in copier (which is a different issue request), but if you have more complex configuration, say in
.copier-answers.yml
you have:So that you can control when you generate a helper bash file to lint golang files whether to fail on any lint issues, or only ones that were introduced by a line your PR touches (i.e. a reviewdog pattern if anyone is interested). In my helper file to lint I want to do something like:
I would like that to also work for:
or even no
go
key. If you can set the jinja2’sEnvironment
’sundefined
is set toChainableUndefined
it will, but with how copier has it you must do:Believe me, I’m the maintainer, I know how this thing works. 😋
I merged recently #317 to clarify this misunderstanding. The fact it works for you is an accident because you didn’t happen to hit any corner cases yet (or because you hit them but didn’t notice), but yes, that’s an unsupported way of updating, and it will always be because of technical reasons explained there.
If you have further questions regarding this subject, please open a new discussion. Let’s keep the issue focused, I hope you don’t mind. 😄