tera icon indicating copy to clipboard operation
tera copied to clipboard

passing a variable string to display it in an html

Open EnricoMucelli opened this issue 2 years ago • 9 comments

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

EnricoMucelli avatar Nov 14 '22 14:11 EnricoMucelli

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

Keats avatar Nov 14 '22 14:11 Keats

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

EnricoMucelli avatar Nov 14 '22 14:11 EnricoMucelli

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

Keats avatar Nov 14 '22 14:11 Keats

i have this errors 3 4 5

EnricoMucelli avatar Nov 14 '22 14:11 EnricoMucelli

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

Keats avatar Nov 14 '22 14:11 Keats

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 avatar Nov 14 '22 14:11 EnricoMucelli

@Keats if i follow the example i get this errors

6 7

EnricoMucelli avatar Nov 14 '22 14:11 EnricoMucelli

tera is the crate name, not your instance of Tera

Keats avatar Nov 14 '22 15:11 Keats

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

EnricoMucelli avatar Nov 15 '22 08:11 EnricoMucelli