sailfish/docs/en/docs/syntax/filters.md

39 lines
793 B
Markdown
Raw Normal View History

2020-07-17 05:06:06 -04:00
# Filters
Filters are used to format the rendered contents.
Example:
=== "Template"
2020-07-17 05:06:06 -04:00
``` rhtml
message: <%\html "foo\nbar" | dbg %>
```
2020-07-17 05:06:06 -04:00
=== "Result"
``` html
message: &quot;foo\nbar&quot;
```
2020-07-17 05:06:06 -04:00
!!! Note
Since `dbg` filter accepts `<T: std::fmt::Debug>` types, that type isn't required to implement [`Render`](https://docs.rs/sailfish/latest/sailfish/runtime/trait.Render.html) trait. That means you can pass the type which doesn't implement `Render` trait.
2020-07-17 05:06:06 -04:00
## Syntax
- Apply filter and HTML escaping
2020-07-17 05:06:06 -04:00
```rhtml
<%\html expression | filter %>
2020-07-17 05:06:06 -04:00
```
- Apply filter only
2020-07-17 05:06:06 -04:00
```rhtml
2020-07-17 05:06:06 -04:00
<%- expression | filter %>
```
## Built-In Filters
Built-In filters can be found in [`sailfish::filter`](https://docs.rs/sailfish/latest/sailfish/runtime/filter/index.html) module.