Created
March 29, 2017 15:22
-
-
Save maliMirkec/6ded4ddfbbfdb382fa8486b16d7b7e99 to your computer and use it in GitHub Desktop.
JavaScript function for replacing template placeholders.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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