-
Notifications
You must be signed in to change notification settings - Fork 2
API format
Given a limited variant of the Mustache template format, and a list of arguments, this function will
Mustache.format(template, [arg1, arg2, arg3, ..., argn])
The template parameter specifies the template to interpolate the arguments with. The template is a limited form of the general Mustache templates in that the tag keys SHOULD be a natural number. All other tag keys will be ignored. Each tag corresponds to the ith argument of the function.
The argi parameter specifies the data object associated with the ith tag key in the template parameter. The relationship is not checked. That is, if more parameters than keys are supplied, the extra parameters are ignored. Similarly, if insufficient parameters are provided, the extra keys will be interpolated as the empty string.
Simple interpolation:
var result = Mustache.format('{{0}} is awesome.', 'Mustache');
result === 'Mustache is awesome.'; // true
Keys do not have to be ordered:
var result = Mustache.format('{{1}} is {{0}}.', 'awesome', 'Mustache');
result === 'Mustache is awesome.'; // true
The parameters can be of any type that Mustache understands:
var result = Mustache.format('{{#0}}{{.}}{{/0}}', [
'Bugs Bunny',
'Daffy Duck',
'Wile E. Coyote'
]);
This function behaves similarly to a poor-man's printf/String.format.