You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: book/src/filters.md
+44-44
Original file line number
Diff line number
Diff line change
@@ -56,13 +56,13 @@ Enable it with Cargo features (see below for more information).
56
56
57
57
Returns the absolute value.
58
58
59
-
```
59
+
```jinja
60
60
{{ -2|abs }}
61
61
```
62
62
63
63
Output:
64
64
65
-
```
65
+
```text
66
66
2
67
67
```
68
68
@@ -71,14 +71,14 @@ Output:
71
71
72
72
Creates a reference to the given argument.
73
73
74
-
```
74
+
```jinja
75
75
{{ "a"|as_ref }}
76
76
{{ self.x|as_ref }}
77
77
```
78
78
79
79
will become:
80
80
81
-
```
81
+
```rust
82
82
&"a"
83
83
&self.x
84
84
```
@@ -88,13 +88,13 @@ will become:
88
88
89
89
Capitalize a value. The first character will be uppercase, all others lowercase:
90
90
91
-
```
91
+
```jinja
92
92
{{ "hello"|capitalize }}
93
93
```
94
94
95
95
Output:
96
96
97
-
```
97
+
```text
98
98
Hello
99
99
```
100
100
@@ -103,12 +103,12 @@ Hello
103
103
104
104
Centers the value in a field of a given width:
105
105
106
-
```
106
+
```jinja
107
107
-{{ "a"|center(5) }}-
108
108
```
109
109
110
110
Output:
111
-
```
111
+
```text
112
112
- a -
113
113
```
114
114
@@ -117,15 +117,15 @@ Output:
117
117
118
118
Dereferences the given argument.
119
119
120
-
```
120
+
```jinja
121
121
{% let s = String::from("a")|as_ref %}
122
122
{% if s|deref == String::from("b") %}
123
123
{% endif %}
124
124
```
125
125
126
126
will become:
127
127
128
-
```
128
+
```rust
129
129
lets=&String::from("a");
130
130
if*s==String::from("b") {}
131
131
```
@@ -135,13 +135,13 @@ if *s == String::from("b") {}
135
135
136
136
Escapes HTML characters in strings:
137
137
138
-
```
138
+
```jinja
139
139
{{ "Escape <>&"|e }}
140
140
```
141
141
142
142
Output:
143
143
144
-
```
144
+
```html
145
145
Escape <>&
146
146
```
147
147
@@ -175,12 +175,12 @@ Escape <>&
175
175
176
176
Returns adequate string representation (in KB, ..) of number of bytes:
177
177
178
-
```
178
+
```jinja
179
179
{{ 1000|filesizeformat }}
180
180
```
181
181
182
182
Output:
183
-
```
183
+
```text
184
184
1 KB
185
185
```
186
186
@@ -195,14 +195,14 @@ Rust). The two arguments are passed through to [`format!()`] by
195
195
the Rinja code generator, but the order is swapped to support filter
196
196
composition.
197
197
198
-
```text
198
+
```jinja
199
199
{{ value|fmt("{:?}") }}
200
200
```
201
201
202
202
As an example, this allows filters to be composed like the following.
203
203
Which is not possible using the `format` filter.
204
204
205
-
```text
205
+
```jinja
206
206
{{ value|capitalize|fmt("{:?}") }}
207
207
```
208
208
@@ -215,7 +215,7 @@ The first argument to this filter must be a string literal (as in normal Rust).
215
215
216
216
All arguments are passed through to [`format!()`] by the Rinja code generator.
217
217
218
-
```
218
+
```jinja
219
219
{{ "{:?}"|format(var) }}
220
220
```
221
221
@@ -226,13 +226,13 @@ All arguments are passed through to [`format!()`] by the Rinja code generator.
226
226
227
227
Indent newlines with width spaces.
228
228
229
-
```
229
+
```jinja
230
230
{{ "hello\nfoo\nbar"|indent(4) }}
231
231
```
232
232
233
233
Output:
234
234
235
-
```
235
+
```text
236
236
hello
237
237
foo
238
238
bar
@@ -243,17 +243,17 @@ hello
243
243
244
244
Joins iterable into a string separated by provided argument.
245
245
246
-
```
246
+
```rust
247
247
array=&["foo", "bar", "bazz"]
248
248
```
249
249
250
-
```
250
+
```jinja
251
251
{{ array|join(", ") }}
252
252
```
253
253
254
254
Output:
255
255
256
-
```
256
+
```text
257
257
foo, bar, bazz
258
258
```
259
259
@@ -264,13 +264,13 @@ Replaces line breaks in plain text with appropriate HTML.
264
264
265
265
A single newline becomes an HTML line break `<br>` and a new line followed by a blank line becomes a paragraph break `<p>`.
266
266
267
-
```
267
+
```jinja
268
268
{{ "hello\nworld\n\nfrom\nrinja"|linebreaks }}
269
269
```
270
270
271
271
Output:
272
272
273
-
```
273
+
```html
274
274
<p>hello<br />world</p><p>from<br />rinja</p>
275
275
```
276
276
@@ -279,13 +279,13 @@ Output:
279
279
280
280
Converts all newlines in a piece of plain text to HTML line breaks.
281
281
282
-
```
282
+
```jinja
283
283
{{ "hello\nworld\n\nfrom\nrinja"|linebreaks }}
284
284
```
285
285
286
286
Output:
287
287
288
-
```
288
+
```html
289
289
hello<br />world<br /><br />from<br />rinja
290
290
```
291
291
@@ -298,13 +298,13 @@ Consecutive double line breaks will be reduced down to a single paragraph break.
298
298
299
299
This is useful in contexts where changing single line breaks to line break tags would interfere with other HTML elements, such as lists and nested `<div>` tags.
0 commit comments