askama icon indicating copy to clipboard operation
askama copied to clipboard

Slice syntax inside of template

Open xrl opened this issue 3 years ago • 1 comments

Is it possible to do quick-and-dirty string slices in a template?

<p class="mb-0">{{ &t.token[0..10] }}</p>

is giving me

error: problems parsing template source at row 16, column 35 near:
       "&t.token[0..10] }}</p>\n                <"...
 --> sparkle-web/src/app/controllers/users/oauth2/index.rs:4:10
  |
4 | #[derive(Template)]
  |          ^^^^^^^^
  |
  = note: this error originates in the derive macro `Template` (in Nightly builds, run with -Z macro-backtrace for more info)

xrl avatar Mar 01 '22 03:03 xrl

t.token.get(0..10).unwrap() would work. The problem is not the slice syntax, actually, but the ampersand is not an operator in Askama.

Kijewski avatar Mar 04 '22 21:03 Kijewski