Template is a simple, in JavaScript written, templating engine.
To use Template you must import the code into your project. You can get the code from GitHub.
<!-- normal-->
<script type="text/javascript" src="./path/to/template/template.js"></script>
<!-- or minified
<script type="text/javascript" src="./path/to/template/template.min.js"></script>
-->
var Template = require('./path/to/template/template.js');
After import, the global object can be used or a new instance, for example in a closed named space, could be used
(function(){
var tmpl = new Template();
// use tmpl var ...
})();
a template to be parsed is a string where multiple templates can be kept separate from each other.
fs.readFile(reqFilePath, (err, data) => {
Template(data); //or Template.parse(data);
});
During rendering, the templates are addressed by the name defined in the template. if no name is passed, the template is addressed without a defined name.
<script type="text/html" id="template">
<{tmpl}>
this is a template without a defined name
<!-- By the way man can import templates into each other
with the keywords: imp, import, inc, inclure, req, require
why so many? I do not know..
-->
<{imp: my name}>
</{tmpl}>
<{tmpl: my name}>
this is a template with a defined name "my name"
</{tmpl}>
</script>
<script type="text/javascript">
(function(){
var tmpl = new Template(document.getElementById("template").innerHTML);
document.body.innerHTML = tmpl.render();
document.body.innerHTML += tmpl.render("my name");
})();
</script>