You can filter values inside template using filters. To use filter for expression, add vertical line filter after object field and filter name inside expression:
<script type="template/karkas" name="demo">
<div class="item">
<b>{{name}}</b>: <span>{{price|currency}}
</div>
</script>
Some filters can have additional arguments, for example - currency filter has currency symbol as optional argument:
{{price|currency:"€"}}
Syntax: {{value|filterName:argument1,argument2}}
All arguments have come after filter name, and separated by coma. Expression must not include space or tabs symbols. Only scalar types, strings and booleans are acceptable as filter arguments.
Compile object or array to HTML template.
Value type: Array|Object;
Arguments
templateName required - Template name;
Stringify object to JSON expression.
Value type: Object;
Capitalize string
Value type: String;
Convert number to currency expresssion (ex. 2.5 => "$ 2.50").
Value type: Number;
Arguments
currencySymbol optional - Currency symbol;
Apply a method from String class to value.
Value type: Any, except Object;
Arguments
method required - String method;
Note: Filter can use more than one argument, according to called function. Example:
<!-- display string length -->
{{title|string:"length"}}
<!-- substring first 15 chars -->
{{text|string:"substring",0,15}}
Call methods from Math JavaScript namespace.
Value type: Number
Arguments
method required - method name;
Note: Filter can use more than one argument, according to called function.
Filter is a regular pure function that receives current Karkas instance as `this` (context), value and parameters and returns a new processed value.
Example:
karkas.addFilter('makeBold', function(value, params) {
console.log(this.filters); // Prints a list of Karkas filters
return `<b>${value}</b>`;
});