-
I want to prompt the user for their name, email and github username, but I'd like to provide sensible defaults (which can be obtained by running |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 7 replies
-
I suppose Copier could retrieve the values itself and inject them in the Jinja context used for questions and answers. We could then set defaults with something like |
Beta Was this translation helpful? Give feedback.
-
Actually, having put the question that way, I realised that this is at least partially covered in the FAQ here. And in fact, writing a simple Jinja extension that just adds stuff to the environment isn't particularly hard: from jinja2.ext import Extension
class TestExtension(Extension):
def __init__(self, environment):
super().__init__(environment)
# add the defaults to the environment
environment.globals["some_variable_name"] = "The value you want" So I guess the answer is that to do this I can write a Jinja extension to do this, and load that extension in Have I missed any subtleties here? As I said, I don't know much about Jinja plugins (the docs say "as long as no template was loaded it’s safe to modify this" - it seems to work here so I assume extensions are initialised early enough that we're OK). It's a bit annoying to have to depend on an extension being installed, but the |
Beta Was this translation helpful? Give feedback.
-
Have you tried with the shell extension? It should let you do something like: # copier.yaml
_jinja_extensions:
- jinja2_shell_extension.ShellExtension
email:
default: "{{ 'git config user.email'|shell }}" |
Beta Was this translation helpful? Give feedback.
Have you tried with the shell extension?
It should let you do something like: