Skip to content

Instantly share code, notes, and snippets.

Created April 3, 2016 17:29
Show Gist options
  • Save anonymous/9ae99f9dc8575f0cdc32cb7e4a9a35eb to your computer and use it in GitHub Desktop.
Save anonymous/9ae99f9dc8575f0cdc32cb7e4a9a35eb to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/wosato
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
// tiny template engine function
function tpl(str,obj){
for(var key in obj) {
str=str.replace(new RegExp('{' + key + '}','g'), obj[key]);
}
return str;
}
// code example
console.clear();
var params = { name: 'John', language: 'JavaScript', skills: 'coding' };
var query = 'Hello {name}, do you want to learn {language} {skills}?';
var res = tpl(query, params);
console.log(res);
</script>
<script id="jsbin-source-javascript" type="text/javascript">// tiny template engine function
function tpl(str,obj){
for(var key in obj) {
str=str.replace(new RegExp('{' + key + '}','g'), obj[key]);
}
return str;
}
// code example
console.clear();
var params = { name: 'John', language: 'JavaScript', skills: 'coding' };
var query = 'Hello {name}, do you want to learn {language} {skills}?';
var res = tpl(query, params);
console.log(res);</script></body>
</html>
// tiny template engine function
function tpl(str,obj){
for(var key in obj) {
str=str.replace(new RegExp('{' + key + '}','g'), obj[key]);
}
return str;
}
// code example
console.clear();
var params = { name: 'John', language: 'JavaScript', skills: 'coding' };
var query = 'Hello {name}, do you want to learn {language} {skills}?';
var res = tpl(query, params);
console.log(res);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment