Support Multiple Templates per Repository #855
Replies: 10 comments 1 reply
-
I've seen this workaround, https://copier.readthedocs.io/en/stable/configuring/#subdirectory, but I don't believe that will support the use case of having different questions per template. Unless it's possible to pull in questions from each subdirectory. If so, that would be 💯 |
Beta Was this translation helpful? Give feedback.
-
nvm, it's in the docs, https://copier.readthedocs.io/en/stable/configuring/#include-other-yaml-files. I think I can work with the combination of those two options. |
Beta Was this translation helpful? Give feedback.
-
@BrutalSimplicity, if you figure out a working example, I would be interested in seeing it. |
Beta Was this translation helpful? Give feedback.
-
Well, I can open this back up. Do you mean the original support in the ticket, or a setup that the configuration supports? |
Beta Was this translation helpful? Give feedback.
-
An example layout, I'm interested doing something similar. |
Beta Was this translation helpful? Give feedback.
-
Hmm, ok. I assume you've seen this. |
Beta Was this translation helpful? Give feedback.
-
Yes, I played with putting extra |
Beta Was this translation helpful? Give feedback.
-
(I am currently including a handful of files in the top level |
Beta Was this translation helpful? Give feedback.
-
Maybe yaml anchors can help you reducing repetition. |
Beta Was this translation helpful? Give feedback.
-
I've come up with a somewhat feasible approach to multiple templates in a repository (possible once a release is created that includes this merged PR) Basically, the repo will contain a single # copier.yml
# Save answers to file namespaced by selected template
_answers_file: ".copier-answers.{{ template }}.yml"
# Store each template under separate subdirectory
_subdirectory: "{{ template }}"
# Don't include the README
_exclude:
- README.md
template:
type: str
choices:
- foo
- bar
- baz
# foo questions
foo_question1:
type: str
when: &foo
"{{ template == 'foo' }}"
foo_question2:
type: str
when: *foo
# bar questions
bar_question1:
type: str
when: &bar
"{{ template == 'bar' }}"
bar_question2:
type: str
when: *bar
# baz questions
baz_question1:
type: str
when: &baz
"{{ template == 'baz' }}"
baz_question2:
type: str
when: *baz For each choice in
This allows you to choose from multiple templates stored in the same repository and ensure that each template choice saves its answers to its own namespaced answers file e.g. |
Beta Was this translation helpful? Give feedback.
-
I would like for
copier
to support multiple templates in a given repository by allowing the subdirectory of the repository to be specified with the vcs ref, and supporting updates by filtering commit history based on the subdirectory and a user-specified suffix/prefix for tags.Alternatively, I can continue to use single repo per template approach that makes template management more difficult on the user and developer.
Beta Was this translation helpful? Give feedback.
All reactions