pub fn random_from_file(args: &HashMap<String, Value>) -> Result<Value>Expand description
A Tera function to sample a random value from a line-delimited file of strings. The filepath
should be passed in as an argument to the path parameter.
Note that the contents of the filepath is read only once and cached.
§Example usage
ⓘ
use tera::{Context, Tera};
use tera_rand::random_from_file;
let mut tera: Tera = Tera::default();
tera.register_function("random_from_file", random_from_file);
let context: Context = Context::new();
let rendered: String = tera
.render_str(r#"{{ random_from_file(path="resources/test/addresses.txt") }}"#, &context)
.unwrap();