gulien / orbit

:satellite: A cross-platform task runner for executing commands and generating files from templates

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ability to include other templates in generate

andrewebdev opened this issue · comments

Expected Behavior

I would like the ability to include the ability to insert other partial templates into my main template.
so let say I have the following traefik.toml file (abbr.):

{{ template "autogen_notice.txt" }}
... traefik config ...

and then in my autogen_notice.txt I have a message warning devops peeps that the file is autogenerated and changes will be overridden if they edit it.

Current Behavior

Currently I get a error:

ERRO[0000] unable to execute the template file ./templates/traefik.toml. Details:
template: traefik.toml:1:12: executing "traefik.toml" at <{{template "./templa...>: template 
"./templates/autogen.txt" not defined

I suspect this is because the included template is not defined in template.ParseFiles, so I'm wondering if there is any kind of workaround for this.

Possible Solution

Could we have a flag in the generate command to specify a list of templates to include in ParseFiles?

Context

There are a couple of instances where I need to re-use config snippets or messages (like the one used above), and currently I'm just resorting to copying them into every file. But it means If I make a edit in one, then I have to remember and update the rest also.

Your Environment

  • Version used (orbit version): 3.1.0
  • Operating System and version: n/a
  • Link to your project: n/a

Indeed, we could imagine a -t --templates flag which allows to specify some templates to parse.
The file orbit-payload.yml could also take a new attribute templates if the user don't want to use every time this new flag:

payload:
    ...

templates:
   -  'path_1'

In the future, those templates could also have their own payloads.

Thank you for the feedback :)