-
Notifications
You must be signed in to change notification settings - Fork 183
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
Add -i/--includes option extending template search path #76
base: main
Are you sure you want to change the base?
Conversation
…arch for jinja templates This is useful for reuse when a set of shared templates are maintained in another directory by using {% include 'lib/header.j2' %} style includes.
Hey, this is great! Lemme take a closer look at this. |
I also have a use for this! Any reason why this is not getting merged? 🤔 |
TBH I forgot about this. Should I merge it? |
jinja2cli/cli.py
Outdated
@@ -212,11 +212,11 @@ def _parse_env(data): | |||
} | |||
|
|||
|
|||
def render(template_path, data, extensions, strict=False): | |||
def render(template_path, data, extensions, strict=False, includes=[]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bad idea to pass empty list as a default argument
explanation here: https://web.archive.org/web/20200221224620/http://effbot.org/zone/default-values.htm
should be something like that:
def render(template_path, data, extensions, strict=False, includes=None):
includes = [] if includes is None else includes
See also mattrobenolt#76 (review) > bad idea to pass empty list as a default argument > explanation here: https://web.archive.org/web/20200221224620/http://effbot.org/zone/default-values.htm > should be something like that: > > ``` > def render(template_path, data, extensions, strict=False, includes=None): > includes = [] if includes is None else includes > ```
Reopen after implementing feedback from @mykhailo-inv-disco |
…ludes flag; some autopeping from tools; add .python-version (pyenv) to .gitignore
@georgespalding Please take a look at this PR: videoplaza#3 . I've added some tests with and without --includes flag. I've got too many templates 🤕 ) |
fix(tests): add tests that call jinja2-cli cmd with and without --inc…
@mattrobenolt Anything else you'd like fixed before merging? |
btw, if you need --includes flag set to templates root but cannot wait for the new version of the jinja2-cli package to be released, as a temporary workaround, you can copy a template into the template root just before rendering it (also don't forget to remove it afterwards), and now you can have predictable imports inside templates. |
thanks for the workaround. |
Would be really great to get this merged :( This version is packaged in most of the distros .... |
+1, I just ran into this issue and currently exploring available options. @mattrobenolt , I noticed the latest release was done over 2 years ago. Is there anything we can do here? |
@mcrozes I'm working on a v1 to tag and clean up the codebase. I hope to get that out in the next few weeks, and I'll get this pulled in. I wanted to solve a few other outstanding issues and drop python2 support as well. This all needs a bit of a modern refresh. |
Thanks for the update @mattrobenolt - Let me know if you need help with anything. |
This is useful for reuse when a set of shared templates are maintained in another directory
by using {% include 'lib/header.j2' %} style includes.
Closes #75