Possible Duplicate:
JavaScript: How should I generate a lot of HTML?
I feel really stupid doing something like this:
var html = '<div><ul>';
for(var i=0; i<10; i++) {
html += '<li>' + i + '</li>';
}
html += '</ul></div>';
$("body").html(html);
Isn't there a way to use templates instead of concatenating strings like that? I know there's the option of populating existing elements with JS and changing the display to block when they need to appear, but it seems rather hackish and annoying, especially when using loops.
I'm open to any front-end template/framework suggestions as well.
This question has probably been asked before, but I couldn't find any clues on SO. Any insight would be greatly appreciated.
EDIT:
To clarify, I'd be interested in something like this:
// li_list.haml
%div
%ul
- for i in #{range}
%li i
// app.js
// require li_list.haml with {range: 10}