This is the main template function that parses a template source file and instanciate it, writing the result into the current template directory (or in a global variable). This procedure should be invoked for each source file that form a GenoM template.
When invoking
template parse
, the last two arguments are the destination file or string. A destination file is specified asfile
file (the filename is relative to the current template output directory). Alternatively, a destination string is specified asstring
var, where var is the name of a global variable in which the template engine will store the result of the source instantiation.The output destination file or string is generated by the template from one or several input source. An input source is typically a source file, but it can also be a string or raw (unprocessed) text. An input source file is specified with
file
file, where file is a file name relative to the template directory. An input source read from a string is specified asstring
text, where text is the text processed by the template engine. Finally, a raw, unprocessed source that is copied verbatim to the destination is specified asraw
text, where text is the text to be output.Additionnaly, each input source, defined as above, can be passed a list of optional arguments by using the special
args
list construction as the first argument of thetemplate parse
command. The list given afterargs
can be retrieved from within the processed template source files from the usual argv variable.Parameters:
- args list
- This optional argument should be followed by a list of arguments to pass to the template source file. It should be the very first argument, otherwise it is ignored. Each element of the list is available from the template source file in the argv array.
- perm mode
- This optional argument may be set to specify the permissions to be set for the created file.
Examples:
template parse file mysrc file mydstWill parse the input file
mysrc
, process it and save the result inmydst
.template parse args {one two} file mysrc file mydstWill do the same as above, but the template code in the input file
mysrc
will have the list{one two}
accessible via the argv variable.template parse string "test" file mydstWill process the string "test" and save the result in
mydst
.