Skip to content

Instantly share code, notes, and snippets.

@phated
Created January 3, 2012 22:25
Show Gist options
  • Save phated/1557270 to your computer and use it in GitHub Desktop.
Save phated/1557270 to your computer and use it in GitHub Desktop.
Extremely basic concept for a templating engine
<html>
<head>
</head>
<body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script>
$(document).ready(function(){
var template = {
div : 'test'
}
function html(key, value) {
if (key !== '') {
var element = ['<',key,'>',value,'</',key,'>'].join('');
return element;
}
return value;
}
var jsonString = JSON.stringify(template, html);
var parsed = JSON.parse(jsonString);
for(element in parsed) {
$('body').prepend(parsed[element]);
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment