Velocity2JS: Templating within
Written by on May 15th, 2007 in Ajax News.
Velocity is a popular templating system for Java developers. Velocity2JS takes the engine and has it output JavaScript functions.
Example Velocity Template
HTML:
JS Output
JAVASCRIPT:
-
-
function helloworld(context) {
-
var text = new StringCat();
-
text.push(’<html><body>Hello ‘);
-
text.push(context.world.name);
-
text.push(’<table>’);
-
for (var i1=0; i1<context .greetings.length; i1++) {
-
var greeting = context.greetings[i1]);
-
text.push(’ <tr> <td>’);
-
text.push(greeting.language);
-
text.push(’</td><td>’);
-
text.push(greeting.text);
-
text.push(’</td> <td>’);
-
}
-
text.push(’</td></context></table></body></html>’);
-
return text.toString();
-
}
-
Source: Ajaxian
Original Article: http://ajaxian.com/archives/velocity2js-templating-within
