pub fn random_string(args: &HashMap<String, Value>) -> Result<Value>Expand description
A Tera function to generate a random String.
By default, this function will generate an alphanumeric string of length 8. For a string with
a different length, pass an integer length to the length parameter in the template.
§Example usage
ⓘ
use tera::{Context, Tera};
use tera_rand::random_string;
let mut tera: Tera = Tera::default();
tera.register_function("random_string", random_string);
let context: Context = Context::new();
// use the default length of 8
let rendered: String = tera
.render_str("{{ random_string() }}", &context)
.unwrap();
// use a custom length of 16
let rendered: String = tera
.render_str("{{ random_string(length=16) }}", &context)
.unwrap();
// use alphanumeric space (which is also the default)
let rendered: String = tera
.render_str(r#"{{ random_string(space="alphanumeric") }}"#, &context)
.unwrap();
// use standard uniform space
let rendered: String = tera
.render_str(r#"{{ random_string(space="standard-uniform") }}"#, &context)
.unwrap();