You can declare converters with your templates - and they will be private to the template. See Registering templates: $.templates(). Look for "Advanced scenarios: Associating private resources with templates".
In addition, the API for registering converters: $.views.converters({...})
also allows you to register a converter (or a set of converters) either globally, or locally just for a specific template. See the section "Adding converters as private resources for a parent template". To make them local, or private, to a template, just pass in the template as last parameter in your converters() call.
So here is a template with its own special converter declared along with the template:
$.templates({
myTemplate: {
markup: "Use my converter {{myconv:name}}",
converters: {
myconv: function(val) { return myCalculatedValue; }
}
}
});
Now {{myconv:...}}
is specific to myTemplate
and won't be available elsewhere.
Now suppose I want to dynamically replace the "myconv", still just within myTemplate
. I can add/change it at any time using the converters()
API:
$.views.converters(
"myconv",
function(val) { return myNewUpdatedCalculatedValue; },
$.templates.myTemplate // Only override it for myTemplate, not globally...
);
Here are some related links:
- http://www.jsviews.com/#samples/jsr/converters
- http://www.jsviews.com/#samples/form-els/converters
- http://www.jsviews.com/#samples/data-link/hover (This one declares a 'private' converter)