View filters modify keypath values in view bindings. Batman.js's view filters are inspired by Liquid filters.
Filters may be used to:
- modify values for presentation (eg,
- mix keypath values and literals (eg,
- modify event handlers (eg,
Batman.View Filters documentation for a full list of available view filters.
You can apply filters to bindings by joining them with
" | ". For example, to apply the
truncate filter with argument
<p data-bind="post.body | truncate 100"></p>
<p> will have the first 100 characters of the post's body. Whenever the
post.body changes, it will be retruncated and the
innerHTML will be updated.
Filter chains can be arbitrarily long:
<span data-bind="knight.name | prepend 'Sir ' | append ', the honourable'"></span>
and filter chains can use other keypaths as arguments to the filters:
<span data-bind="person.name | prepend ' ' | prepend person.title"></span>
innerHTML will be updated whenever the person's name or title changes. Both keypaths are tracked by the binding.