Struct micro_http_async::HtmlConstructor
source ·
[−]pub struct HtmlConstructor;
Expand description
Html Constructor
Loads a html file and constructs it for dynamic web loading
For example, when loading a template, you can pass through variables in a vec to implement them in your page
You can use this for things like user info or other server side information
Alternatively you could create a static page with JavaScript that loads this information from a webapi route on the same server.
Dynamic variables are defined as [ var_name ]
in HTML, and
just var_name
in the Vars hashmap
Here is an example:
<p>[ test_var ]</p>
let mut vars = Vars::new();
vars.insert("test_var".to_string(), Variable::String("Test".to_string()));
This example shows a basic example of how the HTML code matches to Rust.
Please note that if there is no variable defined in the hashmap, it will not update with any dynamic values, and remain static. If the variable in the hashmap doesn’t find the variable in the HTML, nothing will happen there as well.
Implementations
Construct Page
Takes in a file path (to the HTML file) and a Vars
type.
Constructs the HTML page, returning a string value (also assigns all dynamic variables if any)