The folder of template files must be in a directory called template
adjacent to the template manifest.json
Inside the template
directory, you can store files in any shape you like.
Any file that is not a template format will be copied directly to its new location on render. More on that below
Using variables in filenames
Any variable defined in the manifest can be used in file names using handlebars syntax.
For example given the following manifest.json
:
{
"name": "my_template",
"version": "0.1.1",
"metadata": {
"app_archetype": {
"version": "0.1.2"
}
},
"variables": {
"foo": "bar",
}
}
You would use the value of foo
in a filename by adding it to the name like this:
my_{{foo}}_file.rb
Same goes for files too
Rendering files
AppArchetype is capable of rendering erb
and hbs
files
ERB
ERB is a ruby data templating language whereby you specify the values of variables in <%= %>
tags.
For example given the above manifest, if you were wanting to render the value of foo
into a README markdown file, you would:
- Add
.erb
to the name of the text file -README.md.erb
- Then inside the file add the tag:
# Understanding <%= foo %>
On render the erb
extension is removed. So given the above example, you would end up with a README.md
file rendered with the following content:
# Understanding bar
Handlebars
Another option for rendering content is handlebars.
Handlebars is similarly a data templating language which substitutes text between {{
and }}
with variables.
For example given the above manifest, if you were wanting to render the value of foo
into a README markdown file, you would:
- Add
.hbs
to the name of the text file -README.md.hbs
- Then inside the file add the following:
# Understanding {{foo}}
On render the hbs
extension is removed. So given the above example, you would end up with a README.md
file rendered with the following content:
# Understanding bar
Rendering templates
Sometimes it’s handy to render files that are templates into a project (i.e. a .hbs
or .erb
file that will be used as a template in the rendered project). If you want to do this, you need to append .template
to the file to stop the renderer from attempting to render the template.
For example, if you wanted to render a handlebars file called README.md.hbs
, in your template, append .template
onto the end like this: README.md.hbs.template
. When the file is rendered, the contents are copied and the .template
extension is removed.
This allows app archetype templates to include app archetype templates.