Skip to content

Instantly share code, notes, and snippets.

@oslego
Created April 20, 2012 10:25
Show Gist options
  • Save oslego/2427644 to your computer and use it in GitHub Desktop.
Save oslego/2427644 to your computer and use it in GitHub Desktop.
Templates in JavaScript using Array
/*
Neat alternative to JavaScript templating by using an array.
Inspired by Ryan Florence
https://github.com/rpflorence/snack/blob/master/demos/jsonp/demo.js
*/
var h = [],
p = function (){ h.push.apply(h, arguments) },
data = ["one", "two", "three"]
// who needs templates when you have arrays?! :P
p('<ul>')
data.forEach(function(item){
p('<li>' + item + '</li>')
})
p('</ul>')
document.body.innerHTML = h.join('')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment