Add New Templates within An Existing Project¶
This guide covers using Flexlate to add new templates within an existing
project that was not generated from cookiecutter or copier.
If you already
have a project that was previously generated from a template using
cookiecutter or copier and you want to update it with Flexlate,
you should follow the existing project guide.
If you want to create a new project with Flexlate, you should follow
the new project guide.
Initialize the Flexlate Project¶
The fxt init command is used
to initialize a new Flexlate project. You must have a Flexlate project
before you can add any template sources or outputs.
$ fxt init
Initializing flexlate project with default add mode local and user=False in
/tmp/tmp3dpbo39z
⠋ Initializing...
⠋ Initializing...
⠙ Initializing...
✔ Finished initializing flexlate project
Add the Template Source¶
The fxt add source command registers
a template source in the Flexlate configuration file.
$ fxt add source https://github.com/nickderobertis/copier-simple-example
Adding template source...
Adding template source copier-simple-example from
https://github.com/nickderobertis/copier-simple-example
⠋
⠙
⠹
Sucessfully added template source copier-simple-example
⠹
⠹
$ cat flexlate.json
{
"template_sources": [
{
"name": "copier-simple-example",
"path": "https://github.com/nickderobertis/copier-simple-example",
"type": "copier",
"version": "f3fa2c9526c12b3011e0a26108ce141373539bca",
"git_url": "https://github.com/nickderobertis/copier-simple-example",
"target_version": null,
"render_relative_root_in_output": ".",
"render_relative_root_in_template": "output"
}
],
"applied_templates": []
}
You can also specify the --version option to specify which version of
the template you would like to be able to output.
fxt add source https://github.com/nickderobertis/copier-simple-example --version c7e1ba1bfb141e9c577e7c21ee4a5d3ae5dde04d
Add Template Output(s)¶
The fxt add output command renders the
template at the specified location.
$ fxt add output copier-simple-example some/path
Applying template copier-simple-example to /tmp/tmplz_7p19c
Updating 1 applied templates
question1? Format: yaml
my answer
The second question
question2? Format: float
10
create my answer.txt
create temp.txt
✔ Successfully updated template output
✔ Successfully applied template copier-simple-example to /tmp/tmplz_7p19c
$ ls some/path
flexlate.json 'my answer.txt'
If you don’t specify a path to render the template to, the template will be rendered in the current working directory.
fxt add output copier-simple-example
Next Steps¶
See how to update your project to a newer template version.