You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

templates.rs 501B

1234567891011121314151617181920
  1. use lazy_static::lazy_static;
  2. use tera::{Context, Tera};
  3. use tide::Result;
  4. lazy_static! {
  5. pub static ref TEMPLATES: Tera = {
  6. match Tera::new("templates/**/*.html") {
  7. Ok(t) => t,
  8. Err(e) => {
  9. println!("Parsing error(s): {}", e);
  10. ::std::process::exit(1);
  11. }
  12. }
  13. };
  14. }
  15. pub fn render_template(template: &str, context: Context) -> Result<String> {
  16. let html = TEMPLATES.render(template, &context)?;
  17. Ok(html)
  18. }