Crate template_nest

source ·
Expand description

Template engine for Rust.

For more details on the idea behind Template::Nest read:

Examples

More examples in examples/ directory.

Place these files in templates directory: templates/00-simple-page.html:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Simple Page</title>
  </head>
  <body>
    <p>A fairly simple page to test the performance of Template::Nest.</p>
    <p><!--% variable %--></p>
    <!--% simple_component %-->
  </body>
</html>

templates/00-simple-page.html:

<p><!--% variable %--></p>

Those templates can be used in a template hash which is passed to TemplateNest::render to render a page:

use template_nest::TemplateNest;
use template_nest::{filling, Filling};
use std::collections::HashMap;

let nest = TemplateNest::new("templates").unwrap();
let simple_page = filling!(
    "TEMPLATE": "00-simple-page",
    "variable": "Simple Variable",
    "simple_component":  {
        "TEMPLATE":"01-simple-component",
        "variable": "Simple Variable in Simple Component"
    }
);
println!("{}", nest.render(&simple_page).unwrap());

Macros

  • Helper macro for creating instances of Filling.
  • Helper macro for converting types into Filling::Text. It’s used internally by the filling! and filling_list! macros.

Structs

Enums

  • Represents a variable in a template hash, can be a string, another template hash or an array of template hash.