LOADING...

Preview

Pen ID
Unlock Campus Themeforest adv

 

Code
JS
var tmpl = function (t) { 
  var code = 'with(o){return \'' + t.replace(/{{\s*(.+?)\s*}}/g, '\'+($1)+\'') + '\';}';
  return new Function('o', code);
}

var str =
    '
{{ name }} {{ age > 10 ? "old" : "young" }}
'; var data = { name : "Fabrice", age : 5 } // Compile your template var render = tmpl(str); // Use the template document.write(render(data));

Description

This is how you insert Json data in a HTML template without using handlebars or another templating engine...
Term
Wed, 12/27/2017 - 06:58

Related Codes

Pen ID
Pen ID
Pen ID
Square Adv