yew-template
This crate allows you to separate your HTML from your Rust code when using Yew.
Usage
Hello World
Hello [name]!
let html = template_html!;
The code above will actually compile to the following code:
let html = html! ;
Using variables
let name = "World";
let html = template_html!;
Would compile to:
let name = "World";
let html = html! ;
Variables with different identifiers
let last_name = "World";
let html = template_html!;
Using expressions
let name_reversed = Stringfrom;
let html = template_html!;
Which will also display Hello World! as the output is as follows:
let name_reversed = Stringfrom;
let html = html! ;
Note that the brackets around expressions are optional.
In attributes
Hello [name]!
let html = template_html!;
Applied to Yew callbacks
Hello [name]!
let link = ctx.link;
let html = template_html!;
Notes
-
Litteral values are NOT escaped because they come from your code. Using a litteral value of
value closed by quotes" trailing stuffwill cause problems. This will be fixed in a future version. -
You can use multiple top-level elements in your html template file.
License: MIT