This is a little template engine for the Io programming language.
` is evaluated as Io. If an
= exists right after the opening
the result of the evaluated Io will be inserted into the template. For example, if the variable
numberOfCats is set to 2,
I have `=numberOfCats` cats. will result in an output of
I have 2 cats.
It's also possible to do more complex things, like loops. Let's say the variable
catList is set
list("Tim", "Zip") and you have a template that contains this:
My cats are: `catList foreach(catName,``=catName`, `)`
That template will result in an output of
My cats are: Tim, Zip,
Template prototype has the following methods:
compile(filename) - Compile a template and store it in the compiled templates directory. fetch(filename) - Compile a template (it it hasn't already been compiled) and return the template's output. assign(var, value) - Assign a template variable a value.
The following options are available. To set an option, call
set[OptionName](value). For example,
to set the
templateDir option, call
templateDir - The location of the template files. compileDir - Where the compiled templates are stored. forceCompile - Whether or not to recompile templates even if they've already been compiled once. context - Any code in a template is evaluated in terms of the context object. If you want to make additional functions available to the template, put them in this object.
FAQ of questions that have never been asked
Q: I want to use the
` character in my template. How do I do that?
A: Use the templating language to insert it. I.e.:
Q: Why not just use
Sequence interpolate expects the Io code blocks to be complete (parentheses matched, etc.), so
you can't interlace your template content with Io code.