Skip to content

Instantly share code, notes, and snippets.

@blackmambahk
Last active October 14, 2018 11:32
Show Gist options
  • Save blackmambahk/c3a64160a2139efb745a to your computer and use it in GitHub Desktop.
Save blackmambahk/c3a64160a2139efb745a to your computer and use it in GitHub Desktop.
Example of a template 'fmt' directive
{{fmt:'The %1 job is done. What %2 to do next?', @field1, @field2}}
//assumes we have added the Array Generics polyfill
//replacement elements start at 1 not 0
//this code actually goes in the main format utility function
var reFmt1 = /%(\d+)/g;
function formatReplace(str) {
var args = Array.slice(arguments);
return str.replace(reFmt1, function($0, $1) {
return args[$1];
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment