Skip to content

Instantly share code, notes, and snippets.

@maliMirkec
Created March 29, 2017 15:22
Show Gist options
  • Save maliMirkec/6ded4ddfbbfdb382fa8486b16d7b7e99 to your computer and use it in GitHub Desktop.
Save maliMirkec/6ded4ddfbbfdb382fa8486b16d7b7e99 to your computer and use it in GitHub Desktop.
JavaScript function for replacing template placeholders.
var t = function (s, d) {
for (var p in d)
s = s.replace(new RegExp('{' + p + '}', 'g'), d[p]);
return s;
};
// usage
t('<p>{label1}</p><p>{label2}</p>', {
label1: 'Value1'
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment