using jinja extends to create a single file #1465
-
Hi. Thank you for creating this wonderful tool. I've done my best to search for this question, but haven't found anything. Here's what I'm looking for. I would like to create a single file with a default configuration(eg. config.yaml), but also enable modifications to this file for specific apps, which there are many. I'd like to avoid massive logic in the default config template for each app. So I'd like to have a directory of files for the specific apps with a file for each app that would modify the default. (eg. /config/<app_name>.yaml.jinja. config.yaml.jinja ->(pulls aditional config from if it exists)->config/<app_name>.yaml.jinja -> to create a single file config.yaml It seems like the extends inheritance model using blocks in jinja would work perfectly for this. But I think I need some python code to run which does some logic like this?
Does anyone have any ideas for how to implement this? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Welcome to copier! I'm glad you like it 😊 I'm having a bit of trouble to understand the case you're describing. Could you post some example of what you've done and what would you want to avoid please? Thanks! |
Beta Was this translation helpful? Give feedback.
-
I think you're looking for Jinja inheritance and a Jinja include with a dynamic filename. Perhaps like this?
Does this help? |
Beta Was this translation helpful? Give feedback.
I think you're looking for Jinja inheritance and a Jinja include with a dynamic filename. Perhaps like this?
includes/config/_base.yaml.jinja
contains your base config, perhaps with some Jinja blocks as extension hooks.includes/config/<app_name>.yaml.jinja
extend_base.yaml.jinja
, e.g.:template/config.yaml.jinja
includes the app specific config content:_subdirectory: template/
incopier.yml
, otherwise you need to make sure to exclude theincludes/
dir from being copied, and I assume you have a Copier question variableapp_name