Keats / tera

A template engine for Rust based on Jinja2/Django
http://keats.github.io/tera/
MIT License
3.54k stars 283 forks source link

passing a variable string to display it in an html #775

Open EnricoMucelli opened 1 year ago

EnricoMucelli commented 1 year ago

Hi i have a variable with a String and i would like to pass it to a tera template but i don't know how. my main.rs :

image

my html.tera :

image

Keats commented 1 year ago

See the example just above the following link https://tera.netlify.app/docs/#auto-escaping

EnricoMucelli commented 1 year ago

@Keats thank you but nothing is working for me, can you show me a more detailed example please?

Keats commented 1 year ago

It depends on the structure of your user data and whether it's None. If it isn't, something like {{ user.email }} (or whatever property) should work

EnricoMucelli commented 1 year ago

i have this errors 3 4 5

Keats commented 1 year ago

just do context.insert("user", &user), no need to use the json! macro

EnricoMucelli commented 1 year ago

nice, now i have only the context error @Keats

`the trait bound `tera::Context: Serialize` is not satisfied
the following other types implement trait `Serialize`:
&'a T
&'a UncasedStr
&'a mut T
()
(T0, T1)
(T0, T1, T2)
(T0, T1, T2, T3)
(T0, T1, T2, T3, T4)
and 172 othersrustc[E0277](https://doc.rust-lang.org/error-index.html#E0277)
main.rs(30, 5): required by a bound introduced by this call
lib.rs(337, 46): required by a bound in `rocket_dyn_templates::Template::render`
EnricoMucelli commented 1 year ago

@Keats if i follow the example i get this errors

6 7

Keats commented 1 year ago

tera is the crate name, not your instance of Tera

EnricoMucelli commented 1 year ago

@Keats and then what do i have to put insted of tera.render