Struct gtmpl::Template [] [src]

pub struct Template<'a> {
    pub name: &'a str,
    pub text: &'a str,
    pub funcs: Vec<&'a HashMap<String, Func>>,
    pub tree_ids: HashMap<usize, String>,
    pub tree_set: HashMap<String, Tree<'a>>,
}

The main template structure.

Fields

Methods

impl<'a> Template<'a>
[src]

[src]

Creates a new empty template with a given name.

[src]

Adds custom functions to the template.

Example

use std::any::Any;
use std::collections::HashMap;
use std::sync::Arc;

use gtmpl::{Context, Func, Value};

fn hello_world(_args: &[Arc<Any>]) -> Result<Arc<Any>, String> {
  Ok(Arc::new(Value::from("Hello World!")) as Arc<Any>)
}

let mut funcs = HashMap::new();
funcs.insert(String::from("helloWorld"), hello_world as Func);
let mut tmpl = gtmpl::Template::default();
tmpl.add_funcs(&funcs);
tmpl.parse("{{ helloWorld }}").unwrap();
let output = tmpl.render(&Context::empty());
assert_eq!(&output.unwrap(), "Hello World!");

[src]

Parse the given text as template body.

Example

let mut tmpl = gtmpl::Template::default();
tmpl.parse("Hello World!").unwrap();

impl<'a, 'b> Template<'a>
[src]

[src]

[src]

Trait Implementations

impl<'a> Default for Template<'a>
[src]

[src]

Returns the "default value" for a type. Read more