blackmambahk
6/25/2014 - 6:33 AM

Example of a template 'fmt' directive

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];
    });
  }