Added Loader in Jinja2 Environment initialisation#13535
Conversation
|
Hello @onegambler, When attempting to inspect the commits of your pull request for CLA signature status among all authors we encountered commit(s) which were not linked to a GitHub account, thus not allowing us to determine their status(es). The commits that are missing a linked GitHub account are the following:
Unfortunately, we are unable to accept this pull request until this situation is corrected. Here are your options:
We apologize for this inconvenience, especially since it usually bites new contributors to Home Assistant. We hope you understand the need for us to protect ourselves and the great community we all have built legally. The best thing to come out of this is that you only need to fix this once and it benefits the entire Home Assistant and GitHub community. Thanks, I look forward to checking this PR again soon! ❤️ |
|
I'm not sure if that is a feature that is really needed and not a big security problem. Anyway. Revert all of you change and pin only one folder inside configuration to load templates from with |
|
I see. I wasn't aware of concerns around the use of that. Do let me know if this can not be accepted. Also, thank you for your comment. I am not sure I understand, I am also unable to directly import |
|
I think it's ok to add this feature. However, all paths for include/import have to be approved by Also, don't use get_default_config_dir, use |
e6b5a4a to
962c586
Compare
|
I refactored the code. I managed to just modify Not sure about the solution, also I added lazy initialisation on the @balloob I was having a look on how to use The path is used by the loader to decide which is the root path to start from when looking for a template to import, so we can do
Is necessary to add a check on If we were to add the path to the Personally I am keeping my templates to import within Thanks |
|
Yes, |
|
Hi, in this way the user can explicitly specify if and where templates can be found. If no dirs are defined then it will use the "old" TemplateEnvironment. Jinja allows you to use different loaders at the same time, wrapping them with a ChoiceLoader. So for each path defined in Let me know your thoughts, |
|
@onegambler May I ask why this was closed? |
|
Hi dale, Apologies, I just didn't think people were that interested in the change. |
|
The problem with includes is that all templates are rendered within the event loop and thus are not allowed to do any I/O. |
Description:
It adds a
FileSystemLoaderto the Jinja2 Environment object. http://jinja.pocoo.org/docs/2.10/api/#loadersThis will allow to import/include jinja2 templates from other templates:
so that we can export/reuse templates:
{% from script/communication_engine/phrases/greetings.j2' import greeting %}I had to refactor a bit the
get_default_config_dirbecause I was having issue with circular dependency. If there's a nicer/better way to achieve this I'm happy to refactor.Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.github.io#
I will create a PR for the documentation if people are happy with the change/PR
Example entry for
configuration.yaml(if applicable):No changes
Checklist:
tox. Your PR cannot be merged unless tests passIf user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
REQUIREMENTSvariable (example).requirements_all.txtby runningscript/gen_requirements_all.py..coveragerc.If the code does not interact with devices: