In programming web applications is often useful to be able to have a templating function.
This is a templating function (rather a library) that aligns with goals of doing things simply from first principles avoiding complexity, safety by design and separation of concerns.
This is how one would use such a template:
Code Block | breakoutMode | wide|
---|---|---|
| ||
var MAINtemplate=/*html*/`<p>$NAME$ `<p>$Name$ has $$$ID$$$$Amount$ -in $Life$their - Everybody wishes they had more $$$$$</p>$`bank account.</p>$ <p>----</p> `; function MAINrun(){ var Body = document.querySelector('body'); var Data = [{IDAmount : 55, NAMEName : " Fred <the knife>" }, {IDAmount : 45 , NAMEName : "Mary"}]; Body.innerHTML = TEMexpand(Data, MAINtemplate); } READYevent(MAINrun); |
This code would produce:
Code Block |
---|
Fred has $55 in their bank account.
----
Mary has $45 in their bank account.
---- |
TEMexpand is implemented couple of dozen lines of code. You can get the source here.
So why use this instead of a fully featured templating system like Mustache?