Skip to content

Instantly share code, notes, and snippets.

@grevory
Created January 21, 2014 06:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grevory/8535349 to your computer and use it in GitHub Desktop.
Save grevory/8535349 to your computer and use it in GitHub Desktop.
A Pen by Gregory Pike.
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<html>
<div id="template">
<h1>Welcome {{ user }}</h1>
</div>
</html>
var compileData = function(template, data){
var dataIndex;
for (dataIndex in data) {
template = template.replace(new RegExp('{{\\s*' + dataIndex + '\\s*}}', 'gi'), data[dataIndex]);
}
return template;
}
var template = compileData($('#template').html(), {
'user': 'Kevin Flynn'
});
$('#template').html(template);
html {
background: url(http://lovinlosing.com/wallpaper/minimalistic-tron_77649.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
color: #e4b72d;
font-family: sans-serif;
}
h1 {
position: absolute;
top: 60%;
}

Templating

A simple template function that compiles data into the template.

Built for demoing my Andraia Mobile JS framework.

A Pen by Gregory Pike on CodePen.

License.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment